Code Duplication    Length = 78-87 lines in 3 locations

tests/Renderer/CsvRendererTest.php 1 location

@@ 14-92 (lines=79) @@
11
/**
12
 * @author Guillaume Cavana <[email protected]>
13
 */
14
class CsvRendererTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var BufferedIO
18
     */
19
    private $io;
20
21
    protected function setUp()
22
    {
23
        $this->io = new BufferedIO();
24
    }
25
26
    /**
27
     * testCsvRendererError.
28
     */
29
    public function testCsvRendererError()
30
    {
31
        $renderer = RendererFactory::create('csv', $this->io);
32
        $renderer->render($this->createResultCollection(true));
33
34
        $output = <<<CSV
35
"Global Status","Status Code",Name,"Reponse Time","Error Log"
36
FAIL,400,Example,0.42,"Couldn't resolve proxy name"
37
38
CSV;
39
        $this->assertInstanceOf(RendererInterface::class, $renderer);
40
        $this->assertSame($output, $this->io->fetchOutput());
41
    }
42
43
    /**
44
     * testCsvRenderer.
45
     */
46
    public function testCsvRenderer()
47
    {
48
        $renderer = RendererFactory::create('csv', $this->io);
49
        $renderer->render($this->createResultCollection());
50
51
        $output = <<<CSV
52
"Global Status","Status Code",Name,"Reponse Time","Error Log"
53
OK,200,Example,0.42,
54
55
CSV;
56
57
        $this->assertInstanceOf(RendererInterface::class, $renderer);
58
        $this->assertSame($output, $this->io->fetchOutput());
59
    }
60
61
    /**
62
     * createResultCollection.
63
     * @param boolean $hasError
64
     */
65
    public function createResultCollection($hasError = false)
66
    {
67
        $errorLog = null;
68
        if ($hasError) {
69
            $errorLog = curl_strerror(5);
70
        }
71
        $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog);
72
73
        $resultCollection = new ResultCollection();
74
        $resultCollection->append($result);
75
76
        return $resultCollection;
77
    }
78
79
    private function createUrlInfo()
80
    {
81
        return new UrlInfo(
82
            'Example',
83
            'http://example.com',
84
            'GET',
85
            [],
86
            1,
87
            200,
88
            null,
89
            null
90
        );
91
    }
92
}
93

tests/Renderer/ListRendererTest.php 1 location

@@ 14-91 (lines=78) @@
11
/**
12
 * @author Guillaume Cavana <[email protected]>
13
 */
14
class ListRendererTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var BufferedIO
18
     */
19
    private $io;
20
21
    protected function setUp()
22
    {
23
        $this->io = new BufferedIO();
24
    }
25
26
    /**
27
     * testListRendererError.
28
     */
29
    public function testListRendererError()
30
    {
31
        $renderer = RendererFactory::create('list', $this->io);
32
        $renderer->render($this->createResultCollection(true));
33
34
        $output = <<<LIST
35
[FAIL][400] Example - 0.42 - Couldn't resolve proxy name
36
37
LIST;
38
39
        $this->assertInstanceOf(RendererInterface::class, $renderer);
40
        $this->assertSame($output, $this->io->fetchOutput());
41
    }
42
43
    /**
44
     * testTableRenderer.
45
     */
46
    public function testListRenderer()
47
    {
48
        $renderer = RendererFactory::create('list', $this->io);
49
        $renderer->render($this->createResultCollection());
50
51
        $output = <<<LIST
52
[OK][200] Example - 0.42
53
54
LIST;
55
56
        $this->assertInstanceOf(RendererInterface::class, $renderer);
57
        $this->assertSame($output, $this->io->fetchOutput());
58
    }
59
60
    /**
61
     * createResultCollection.
62
     * @param boolean $hasError
63
     */
64
    public function createResultCollection($hasError = false)
65
    {
66
        $errorLog = null;
67
        if ($hasError) {
68
            $errorLog = curl_strerror(5);
69
        }
70
        $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog);
71
72
        $resultCollection = new ResultCollection();
73
        $resultCollection->append($result);
74
75
        return $resultCollection;
76
    }
77
78
    private function createUrlInfo()
79
    {
80
        return new UrlInfo(
81
            'Example',
82
            'http://example.com',
83
            'GET',
84
            [],
85
            1,
86
            200,
87
            null,
88
            null
89
        );
90
    }
91
}
92

tests/Renderer/TableRendererTest.php 1 location

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