Code Duplication    Length = 85-93 lines in 2 locations

tests/Renderer/ListRendererTest.php 1 location

@@ 28-112 (lines=85) @@
25
/**
26
 * @author Guillaume Cavana <[email protected]>
27
 */
28
class ListRendererTest extends \PHPUnit_Framework_TestCase
29
{
30
    /**
31
     * @var BufferedIO
32
     */
33
    private $io;
34
35
    protected function setUp()
36
    {
37
        $this->io = new BufferedIO();
38
    }
39
40
    /**
41
     * testListRendererError.
42
     */
43
    public function testListRendererError()
44
    {
45
        $renderer = RendererFactory::create('list', $this->io);
46
        $renderer->render($this->createResultCollection(true));
47
48
        $output = <<<LIST
49
[FAIL][400] Example - 0.42 - Couldn't resolve proxy name - Validation Error
50
51
LIST;
52
53
        $this->assertInstanceOf(RendererInterface::class, $renderer);
54
        $this->assertSame($output, $this->io->fetchOutput());
55
    }
56
57
    /**
58
     * testTableRenderer.
59
     */
60
    public function testListRenderer()
61
    {
62
        $renderer = RendererFactory::create('list', $this->io);
63
        $renderer->render($this->createResultCollection());
64
65
        $output = <<<LIST
66
[OK][200] Example - 0.42
67
68
LIST;
69
70
        $this->assertInstanceOf(RendererInterface::class, $renderer);
71
        $this->assertSame($output, $this->io->fetchOutput());
72
    }
73
74
    /**
75
     * createResultCollection.
76
     *
77
     * @param bool $hasError
78
     *
79
     * @return ResultCollection
80
     */
81
    public function createResultCollection($hasError = false)
82
    {
83
        $errorLog = null;
84
        $validationErrorLog = null;
85
86
        if ($hasError) {
87
            $errorLog = curl_strerror(5);
88
            $validationErrorLog = 'Validation Error';
89
        }
90
91
        $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog, $hasError ? false : true, $validationErrorLog);
92
93
        $resultCollection = new ResultCollection();
94
        $resultCollection->append($result);
95
96
        return $resultCollection;
97
    }
98
99
    private function createUrlInfo()
100
    {
101
        return new UrlInfo(
102
            'Example',
103
            'http://example.com',
104
            'GET',
105
            [],
106
            1,
107
            200,
108
            (new Validator()),
109
            null,
110
            null
111
        );
112
    }
113
}
114

tests/Renderer/TableRendererTest.php 1 location

@@ 28-120 (lines=93) @@
25
/**
26
 * @author Guillaume Cavana <[email protected]>
27
 */
28
class TableRendererTest extends \PHPUnit_Framework_TestCase
29
{
30
    /**
31
     * @var BufferedIO
32
     */
33
    private $io;
34
35
    protected function setUp()
36
    {
37
        $this->io = new BufferedIO();
38
    }
39
40
    /**
41
     * testTableRendererError.
42
     */
43
    public function testTableRendererError()
44
    {
45
        $renderer = RendererFactory::create('table', $this->io);
46
        $renderer->render($this->createResultCollection(true));
47
48
        $output = <<<TABLE
49
+--------+--------+---------+----------+--------------------+------------------+
50
| Global | Status | Name    | Response | Http Error Log     | Validator Error  |
51
| Status | Code   |         | Time     |                    | Log              |
52
+--------+--------+---------+----------+--------------------+------------------+
53
| FAIL   | 400    | Example | 0.42     | Couldn't           | Validation Error |
54
|        |        |         |          | resolve proxy name |                  |
55
+--------+--------+---------+----------+--------------------+------------------+
56
57
TABLE;
58
        $this->assertInstanceOf(RendererInterface::class, $renderer);
59
        $this->assertSame($output, $this->io->fetchOutput());
60
    }
61
62
    /**
63
     * testTableRenderer.
64
     */
65
    public function testTableRenderer()
66
    {
67
        $renderer = RendererFactory::create('table', $this->io);
68
        $renderer->render($this->createResultCollection());
69
70
        $output = <<<TABLE
71
+--------+--------+---------+----------+----------------+---------------------+
72
| Global | Status | Name    | Response | Http Error Log | Validator Error Log |
73
| Status | Code   |         | Time     |                |                     |
74
+--------+--------+---------+----------+----------------+---------------------+
75
| OK     | 200    | Example | 0.42     |                |                     |
76
+--------+--------+---------+----------+----------------+---------------------+
77
78
TABLE;
79
        $this->assertInstanceOf(RendererInterface::class, $renderer);
80
        $this->assertSame($output, $this->io->fetchOutput());
81
    }
82
83
    /**
84
     * createResultCollection.
85
     *
86
     * @param bool $hasError
87
     */
88
    public function createResultCollection($hasError = false)
89
    {
90
        $errorLog = null;
91
        $validationErrorLog = null;
92
93
        if ($hasError) {
94
            $errorLog = curl_strerror(5);
95
            $validationErrorLog = 'Validation Error';
96
        }
97
98
        $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog, $hasError ? false : true, $validationErrorLog);
99
100
        $resultCollection = new ResultCollection();
101
        $resultCollection->append($result);
102
103
        return $resultCollection;
104
    }
105
106
    private function createUrlInfo()
107
    {
108
        return new UrlInfo(
109
            'Example',
110
            'http://example.com',
111
            'GET',
112
            [],
113
            1,
114
            200,
115
            (new Validator()),
116
            null,
117
            null
118
        );
119
    }
120
}
121