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 |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var BufferedIO |
18
|
|
|
*/ |
19
|
|
|
private $io; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->io = new BufferedIO(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* testTableRenderer. |
28
|
|
|
*/ |
29
|
|
|
public function testTableRenderer() |
30
|
|
|
{ |
31
|
|
|
$renderer = RendererFactory::create('table', $this->io); |
32
|
|
|
$renderer->render($this->createResultCollection()); |
33
|
|
|
|
34
|
|
|
$output = <<<TABLE |
35
|
|
|
+---------------+-------------+---------+---------------+ |
36
|
|
|
| Global Status | Status Code | Name | Response Time | |
37
|
|
|
+---------------+-------------+---------+---------------+ |
38
|
|
|
| FAIL | 200 | Example | 0.42 | |
39
|
|
|
+---------------+-------------+---------+---------------+ |
40
|
|
|
|
41
|
|
|
TABLE; |
42
|
|
|
$this->assertInstanceOf(RendererInterface::class, $renderer); |
43
|
|
|
$this->assertSame($output, $this->io->fetchOutput()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* createResultCollection. |
48
|
|
|
*/ |
49
|
|
|
public function createResultCollection() |
50
|
|
|
{ |
51
|
|
|
$result = new Result($this->createUrlInfo(), 200, 0.42); |
52
|
|
|
|
53
|
|
|
$resultCollection = new ResultCollection(); |
54
|
|
|
$resultCollection->append($result); |
55
|
|
|
|
56
|
|
|
return $resultCollection; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function createUrlInfo() |
60
|
|
|
{ |
61
|
|
|
return new UrlInfo( |
62
|
|
|
'Example', |
63
|
|
|
'http://example.com', |
64
|
|
|
'GET', |
65
|
|
|
[], |
66
|
|
|
1, |
67
|
|
|
404, |
68
|
|
|
null, |
69
|
|
|
null |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.