Passed
Push — master ( 5ba82c...2c1d46 )
by Kyle
02:49 queued 11s
created

testRendererOutputsForReportWithContents()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 57
rs 8.9381
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Renderer;
19
20
use PHPMD\AbstractTest;
21
use PHPMD\Stubs\WriterStub;
22
23
/**
24
 * Test case for the ansi renderer implementation.
25
 *
26
 * @covers \PHPMD\Renderer\AnsiRendererTest
27
 */
28
class AnsiRendererTest extends AbstractTest
29
{
30
    /**
31
     * testRendererOutputsForReportWithContents
32
     *
33
     * @return void
34
     */
35
    public function testRendererOutputsForReportWithContents()
36
    {
37
        $writer = new WriterStub();
38
39
        $violations = array(
40
            $this->getRuleViolationMock('/bar.php', 1),
41
            $this->getRuleViolationMock('/foo.php', 2),
42
            $this->getRuleViolationMock('/foo.php', 3),
43
        );
44
45
        $errors = array(
46
            $this->getErrorMock(),
47
        );
48
49
        $report = $this->getReportMock(0);
50
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            ->method('getRuleViolations')
52
            ->will($this->returnValue(new \ArrayIterator($violations)));
53
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
            ->method('isEmpty')
55
            ->will($this->returnValue(false));
56
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
            ->method('hasErrors')
58
            ->will($this->returnValue(true));
59
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
            ->method('getErrors')
61
            ->will($this->returnValue(new \ArrayIterator($errors)));
62
        $report->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            ->method('getElapsedTimeInMillis')
64
            ->will($this->returnValue(200));
65
66
        $renderer = new AnsiRenderer();
67
        $renderer->setWriter($writer);
68
69
        $renderer->start();
70
        $renderer->renderReport($report);
71
        $renderer->end();
72
73
        $expectedChunks = [
74
            PHP_EOL . "FILE: /bar.php" . PHP_EOL . "--------------" . PHP_EOL,
75
            " 1 | \e[31mVIOLATION\e[0m | Test description" . PHP_EOL,
76
            PHP_EOL . "FILE: /foo.php" . PHP_EOL . "--------------" . PHP_EOL,
77
            " 2 | \e[31mVIOLATION\e[0m | Test description" . PHP_EOL,
78
            " 3 | \e[31mVIOLATION\e[0m | Test description" . PHP_EOL,
79
            PHP_EOL . "\e[33mERROR\e[0m while parsing /foo/baz.php" . PHP_EOL . "--------------------------------" . PHP_EOL,
80
            "Error in file \"/foo/baz.php\"" . PHP_EOL,
81
            PHP_EOL . "Found 3 violations and 1 error in 200ms" . PHP_EOL,
82
        ];
83
84
        foreach($writer->getChunks() as $i => $chunk) {
85
            $this->assertEquals(
86
                $expectedChunks[$i],
87
                $chunk,
88
                sprintf('Chunk %s did not match expected string', $i)
89
            );
90
        }
91
    }
92
93
    /**
94
     * testRendererOutputsForReportWithoutContents
95
     *
96
     * @return void
97
     */
98
    public function testRendererOutputsForReportWithoutContents()
99
    {
100
        $writer = new WriterStub();
101
102
        $report = $this->getReportMock(0);
103
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
            ->method('getRuleViolations')
105
            ->will($this->returnValue(new \ArrayIterator([])));
106
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
            ->method('isEmpty')
108
            ->will($this->returnValue(true));
109
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
            ->method('hasErrors')
111
            ->will($this->returnValue(false));
112
        $report->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
113
            ->method('getErrors')
114
            ->will($this->returnValue(new \ArrayIterator([])));
115
        $report->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<PHPMD\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
            ->method('getElapsedTimeInMillis')
117
            ->will($this->returnValue(200));
118
119
        $renderer = new AnsiRenderer();
120
        $renderer->setWriter($writer);
121
122
        $renderer->start();
123
        $renderer->renderReport($report);
124
        $renderer->end();
125
126
        $expectedChunks = [
127
            PHP_EOL . "Found 0 violations and 0 errors in 200ms" . PHP_EOL,
128
            PHP_EOL . "\e[32mNo mess detected\e[0m" . PHP_EOL,
129
        ];
130
131
        foreach($writer->getChunks() as $i => $chunk) {
132
            $this->assertEquals(
133
                $expectedChunks[$i],
134
                $chunk,
135
                sprintf('Chunk %s did not match expected string', $i)
136
            );
137
        }
138
    }
139
}
140