ListRendererTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 98.84 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 5
Bugs 0 Features 2
Metric Value
c 5
b 0
f 2
dl 85
loc 86
rs 10
wmc 8
lcom 1
cbo 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 4 4 1
A testListRendererError() 13 13 1
A testListRenderer() 13 13 1
A createResultCollection() 17 17 4
A createUrlInfo() 14 14 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
/*
4
 * This file is part of the hogosha-monitor package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Hogosha\Monitor\Renderer;
17
18
use Hogosha\Monitor\Model\Result;
19
use Hogosha\Monitor\Model\ResultCollection;
20
use Hogosha\Monitor\Model\UrlInfo;
21
use Hogosha\Monitor\Validator\Validator;
22
use Webmozart\Console\Api\IO\IO;
23
use Webmozart\Console\IO\BufferedIO;
24
25
/**
26
 * @author Guillaume Cavana <[email protected]>
27
 */
28 View Code Duplication
class ListRendererTest 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...
29
{
30
    /**
31
     * @var BufferedIO
32
     */
33
    private $io;
34
35
    protected function setUp()
36
    {
37
        $this->io = new BufferedIO();
38
    }
39
40
    /**
41
     * testListRendererError.
42
     */
43
    public function testListRendererError()
44
    {
45
        $renderer = RendererFactory::create('list', $this->io);
46
        $renderer->render($this->createResultCollection(true));
47
48
        $output = <<<LIST
49
[FAIL][400] Example - 0.42 - Couldn't resolve proxy name - Validation Error
50
51
LIST;
52
53
        $this->assertInstanceOf(RendererInterface::class, $renderer);
54
        $this->assertSame($output, $this->io->fetchOutput());
55
    }
56
57
    /**
58
     * testTableRenderer.
59
     */
60
    public function testListRenderer()
61
    {
62
        $renderer = RendererFactory::create('list', $this->io);
63
        $renderer->render($this->createResultCollection());
64
65
        $output = <<<LIST
66
[OK][200] Example - 0.42
67
68
LIST;
69
70
        $this->assertInstanceOf(RendererInterface::class, $renderer);
71
        $this->assertSame($output, $this->io->fetchOutput());
72
    }
73
74
    /**
75
     * createResultCollection.
76
     *
77
     * @param bool $hasError
78
     *
79
     * @return ResultCollection
80
     */
81
    public function createResultCollection($hasError = false)
82
    {
83
        $errorLog = null;
84
        $validationErrorLog = null;
85
86
        if ($hasError) {
87
            $errorLog = curl_strerror(5);
88
            $validationErrorLog = 'Validation Error';
89
        }
90
91
        $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog, $hasError ? false : true, $validationErrorLog);
92
93
        $resultCollection = new ResultCollection();
94
        $resultCollection->append($result);
95
96
        return $resultCollection;
97
    }
98
99
    private function createUrlInfo()
100
    {
101
        return new UrlInfo(
102
            'Example',
103
            'http://example.com',
104
            'GET',
105
            [],
106
            1,
107
            200,
108
            (new Validator()),
109
            null,
110
            null
111
        );
112
    }
113
}
114