Completed
Pull Request — master (#912)
by
unknown
07:49
created

TextRendererTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 10
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A creation() 10 10 1
B rendering() 0 25 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method 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...
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