Completed
Push — master ( b829e8...5d217f )
by Guillaume
02:31
created

CsvRendererTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 46
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 4 4 1
A testTableRenderer() 14 14 1
A createResultCollection() 9 9 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
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\CsvRenderer;
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 CsvRendererTest 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...
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('list', $this->io);
36
        $renderer->render($this->createResultCollection());
37
38
        $output = <<<TABLE
39
Name,Status,"Reponse Time"
40
Example,200,0.42
41
42
TABLE;
43
44
        $this->assertInstanceOf(RendererInterface::class, $renderer);
45
        $this->assertSame($output, $this->io->fetchOutput());
46
    }
47
48
    /**
49
     * createResultCollection.
50
     * @return void
51
     */
52
    public function createResultCollection()
53
    {
54
        $result = new Result('Example', 200, 0.42);
55
56
        $resultCollection = new ResultCollection();
57
        $resultCollection->append($result);
58
59
        return $resultCollection;
60
    }
61
}
62