1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* this file is part of magerun |
4
|
|
|
* |
5
|
|
|
* @author Tom Klingenberg <https://github.com/ktomk> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace N98\Util\Console\Helper\Table\Renderer; |
9
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Output\StreamOutput; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class TextRendererTest |
14
|
|
|
* |
15
|
|
|
* @covers N98\Util\Console\Helper\Table\Renderer\TextRenderer |
16
|
|
|
* @package N98\Util\Console\Helper\Table\Renderer |
17
|
|
|
*/ |
18
|
|
|
class TextRendererTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
public function creation() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$renderer = new TextRenderer(); |
26
|
|
|
$this->assertInstanceOf(__NAMESPACE__ . '\\TextRenderer', $renderer); |
27
|
|
|
|
28
|
|
|
$renderFactory = new RendererFactory(); |
29
|
|
|
|
30
|
|
|
$renderer = $renderFactory->create('text'); |
31
|
|
|
$this->assertInstanceOf(__NAMESPACE__ . '\\TextRenderer', $renderer); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function rendering() |
38
|
|
|
{ |
39
|
|
|
$renderer = new TextRenderer(); |
40
|
|
|
$output = new StreamOutput(fopen('php://memory', 'w', false)); |
41
|
|
|
|
42
|
|
|
$rows = array( |
43
|
|
|
array('Column1' => 'Value A1', 'Column2' => 'A2 is another value that there is'), |
44
|
|
|
array(1, "multi\nline\nftw"), |
45
|
|
|
array("C1 cell here!", new \SimpleXMLElement('<r>PHP Magic->toString() test</r>')), |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$expected = '+---------------+-----------------------------------+ |
49
|
|
|
| Column1 | Column2 | |
50
|
|
|
+---------------+-----------------------------------+ |
51
|
|
|
| Value A1 | A2 is another value that there is | |
52
|
|
|
| 1 | multi | |
53
|
|
|
| | line | |
54
|
|
|
| | ftw | |
55
|
|
|
| C1 cell here! | PHP Magic->toString() test | |
56
|
|
|
+---------------+-----------------------------------+' . "\n"; |
57
|
|
|
|
58
|
|
|
$renderer->render($output, $rows); |
59
|
|
|
|
60
|
|
|
$this->assertEquals($expected, $this->getOutputBuffer($output)); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.