Completed
Push — master ( 084e6b...eff98c )
by Guillaume
05:15
created

TableRendererTest::testTableRendererError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 18
loc 18
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Hogosha\Monitor\Renderer;
4
5
use Hogosha\Monitor\Model\Result;
6
use Hogosha\Monitor\Model\ResultCollection;
7
use Hogosha\Monitor\Model\UrlInfo;
8
use Webmozart\Console\Api\IO\IO;
9
use Webmozart\Console\IO\BufferedIO;
10
11
/**
12
 * @author Guillaume Cavana <[email protected]>
13
 */
14 View Code Duplication
class TableRendererTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
The call to TableRendererTest::createUrlInfo() has too many arguments starting with $hasError.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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