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\Renderer\RendererFactory; |
8
|
|
|
use Hogosha\Monitor\Renderer\RendererInterface; |
9
|
|
|
use Hogosha\Monitor\Renderer\TableRenderer; |
10
|
|
|
use Webmozart\Console\Api\IO\IO; |
11
|
|
|
use Webmozart\Console\IO\BufferedIO; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Guillaume Cavana <[email protected]> |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class TableRendererTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var BufferedIO |
21
|
|
|
*/ |
22
|
|
|
private $io; |
23
|
|
|
|
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->io = new BufferedIO(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* testTableRenderer. |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function testTableRenderer() |
34
|
|
|
{ |
35
|
|
|
$renderer = RendererFactory::create('table', $this->io); |
36
|
|
|
$renderer->render($this->createResultCollection()); |
37
|
|
|
|
38
|
|
|
$output = <<<TABLE |
39
|
|
|
+---------+--------+---------------+ |
40
|
|
|
| Name | Status | Response Time | |
41
|
|
|
+---------+--------+---------------+ |
42
|
|
|
| Example | 200 | 0.42 | |
43
|
|
|
+---------+--------+---------------+ |
44
|
|
|
|
45
|
|
|
TABLE; |
46
|
|
|
|
47
|
|
|
$this->assertInstanceOf(RendererInterface::class, $renderer); |
48
|
|
|
$this->assertSame($output, $this->io->fetchOutput()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* createResultCollection. |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function createResultCollection() |
56
|
|
|
{ |
57
|
|
|
$result = new Result('Example', 200, 0.42); |
58
|
|
|
|
59
|
|
|
$resultCollection = new ResultCollection(); |
60
|
|
|
$resultCollection->append($result); |
61
|
|
|
|
62
|
|
|
return $resultCollection; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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.