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\ProcessingError; |
22
|
|
|
use PHPMD\Stubs\WriterStub; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Test case for the text renderer implementation. |
26
|
|
|
* |
27
|
|
|
* @covers \PHPMD\Renderer\TextRenderer |
28
|
|
|
*/ |
29
|
|
|
class TextRendererTest extends AbstractTest |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* testRendererCreatesExpectedNumberOfTextEntries |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function testRendererCreatesExpectedNumberOfTextEntries() |
37
|
|
|
{ |
38
|
|
|
// Create a writer instance. |
39
|
|
|
$writer = new WriterStub(); |
40
|
|
|
|
41
|
|
|
$violations = array( |
42
|
|
|
$this->getRuleViolationMock('/bar.php', 1), |
43
|
|
|
$this->getRuleViolationMock('/foo.php', 2), |
44
|
|
|
$this->getRuleViolationMock('/foo.php', 3), |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$report = $this->getReportMock(0); |
48
|
|
|
$report->expects($this->once()) |
49
|
|
|
->method('getRuleViolations') |
50
|
|
|
->willReturn(new \ArrayIterator($violations)); |
51
|
|
|
$report->expects($this->once()) |
52
|
|
|
->method('getErrors') |
53
|
|
|
->willReturn(new \ArrayIterator(array())); |
54
|
|
|
|
55
|
|
|
$renderer = new TextRenderer(); |
56
|
|
|
$renderer->setWriter($writer); |
57
|
|
|
|
58
|
|
|
$renderer->start(); |
59
|
|
|
$renderer->renderReport($report); |
60
|
|
|
$renderer->end(); |
61
|
|
|
|
62
|
|
|
$this->assertEquals( |
63
|
|
|
"/bar.php:1\tTest description" . PHP_EOL . |
64
|
|
|
"/foo.php:2\tTest description" . PHP_EOL . |
65
|
|
|
"/foo.php:3\tTest description" . PHP_EOL, |
66
|
|
|
$writer->getData() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* testRendererAddsProcessingErrorsToTextReport |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function testRendererAddsProcessingErrorsToTextReport() |
76
|
|
|
{ |
77
|
|
|
// Create a writer instance. |
78
|
|
|
$writer = new WriterStub(); |
79
|
|
|
|
80
|
|
|
$errors = array( |
81
|
|
|
new ProcessingError('Failed for file "/tmp/foo.php".'), |
82
|
|
|
new ProcessingError('Failed for file "/tmp/bar.php".'), |
83
|
|
|
new ProcessingError('Failed for file "/tmp/baz.php".'), |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$report = $this->getReportMock(0); |
87
|
|
|
$report->expects($this->once()) |
88
|
|
|
->method('getRuleViolations') |
89
|
|
|
->willReturn(new \ArrayIterator(array())); |
90
|
|
|
$report->expects($this->once()) |
91
|
|
|
->method('getErrors') |
92
|
|
|
->willReturn(new \ArrayIterator($errors)); |
93
|
|
|
|
94
|
|
|
$renderer = new TextRenderer(); |
95
|
|
|
$renderer->setWriter($writer); |
96
|
|
|
|
97
|
|
|
$renderer->start(); |
98
|
|
|
$renderer->renderReport($report); |
99
|
|
|
$renderer->end(); |
100
|
|
|
|
101
|
|
|
$this->assertEquals( |
102
|
|
|
"/tmp/foo.php\t-\tFailed for file \"/tmp/foo.php\"." . PHP_EOL . |
103
|
|
|
"/tmp/bar.php\t-\tFailed for file \"/tmp/bar.php\"." . PHP_EOL . |
104
|
|
|
"/tmp/baz.php\t-\tFailed for file \"/tmp/baz.php\"." . PHP_EOL, |
105
|
|
|
$writer->getData() |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|