1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Test case |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2007-2010, Mayflower GmbH |
7
|
|
|
* All rights reserved. |
8
|
|
|
* |
9
|
|
|
* Redistribution and use in source and binary forms, with or without |
10
|
|
|
* modification, are permitted provided that the following conditions |
11
|
|
|
* are met: |
12
|
|
|
* |
13
|
|
|
* * Redistributions of source code must retain the above copyright |
14
|
|
|
* notice, this list of conditions and the following disclaimer. |
15
|
|
|
* |
16
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
17
|
|
|
* notice, this list of conditions and the following disclaimer in |
18
|
|
|
* the documentation and/or other materials provided with the |
19
|
|
|
* distribution. |
20
|
|
|
* |
21
|
|
|
* * Neither the name of Mayflower GmbH nor the names of his |
22
|
|
|
* contributors may be used to endorse or promote products derived |
23
|
|
|
* from this software without specific prior written permission. |
24
|
|
|
* |
25
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
26
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
27
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
28
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
29
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
30
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
31
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
32
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
33
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
34
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
35
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
36
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
37
|
|
|
* |
38
|
|
|
* @category PHP_CodeBrowser |
39
|
|
|
* |
40
|
|
|
* @author Simon Kohlmeyer <[email protected] |
41
|
|
|
* |
42
|
|
|
* @copyright 2007-2010 Mayflower GmbH |
43
|
|
|
* |
44
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
45
|
|
|
* |
46
|
|
|
* @version SVN: $Id$ |
47
|
|
|
* |
48
|
|
|
* @link http://www.phpunit.de/ |
49
|
|
|
* |
50
|
|
|
* @since File available since 0.9.0 |
51
|
|
|
*/ |
52
|
|
|
|
53
|
|
|
namespace PHPCodeBrowser\Tests\Plugins; |
54
|
|
|
|
55
|
|
|
use DOMDocument; |
56
|
|
|
use PHPCodeBrowser\File; |
57
|
|
|
use PHPCodeBrowser\Issue; |
58
|
|
|
use PHPCodeBrowser\IssueXML; |
59
|
|
|
use PHPCodeBrowser\Plugins\ErrorCRAP; |
60
|
|
|
use PHPCodeBrowser\Tests\AbstractTestCase; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* ErrorCRAPTest |
64
|
|
|
* |
65
|
|
|
* @category PHP_CodeBrowser |
66
|
|
|
* |
67
|
|
|
* @author Simon Kohlmeyer <[email protected]> |
68
|
|
|
* |
69
|
|
|
* @copyright 2007-2010 Mayflower GmbH |
70
|
|
|
* |
71
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
72
|
|
|
* |
73
|
|
|
* @version Release: @package_version@ |
74
|
|
|
* |
75
|
|
|
* @link http://www.phpunit.de/ |
76
|
|
|
* |
77
|
|
|
* @since Class available since 0.9.0 |
78
|
|
|
*/ |
79
|
|
|
class ErrorCRAPTest extends AbstractTestCase |
80
|
|
|
{ |
81
|
|
|
/** |
82
|
|
|
* The object to test. |
83
|
|
|
* |
84
|
|
|
* @var ErrorCRAP |
85
|
|
|
*/ |
86
|
|
|
protected $errorCrap; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The xml string to test the plugin against. |
90
|
|
|
* |
91
|
|
|
* @var string |
92
|
|
|
*/ |
93
|
|
|
protected $testXml = <<<HERE |
94
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
95
|
|
|
<coverage generated="1279366386"> |
96
|
|
|
<project timestamp="1279366386"> |
97
|
|
|
<file name="/test/file"> |
98
|
|
|
<class name="Class" |
99
|
|
|
namespace="global" |
100
|
|
|
fullPackage="Full_Package" |
101
|
|
|
category="Category" |
102
|
|
|
package="Package"> |
103
|
|
|
</class> |
104
|
|
|
<line num="50" type="stmt" count="1"/> |
105
|
|
|
<line num="143" type="method" name="method_1" crap="1" count="3"/> |
106
|
|
|
<line num="144" type="stmt" count="3"/> |
107
|
|
|
<line num="145" type="stmt" count="3"/> |
108
|
|
|
<line num="162" type="method" name="method_2" crap="100" count="3"/> |
109
|
|
|
<line num="164" type="stmt" count="3"/> |
110
|
|
|
<line num="165" type="stmt" count="3"/> |
111
|
|
|
</file> |
112
|
|
|
<file name="/has/no/crap"> |
113
|
|
|
<class name="NoCrapClass" |
114
|
|
|
namespace="global" |
115
|
|
|
fullPackage="Full_Package" |
116
|
|
|
category="Category" |
117
|
|
|
package="Package"> |
118
|
|
|
</class> |
119
|
|
|
<line num="50" type="stmt" count="1"/> |
120
|
|
|
<line num="143" type="method" name="method_1" count="3"/> |
121
|
|
|
<line num="144" type="stmt" count="3"/> |
122
|
|
|
<line num="145" type="stmt" count="3"/> |
123
|
|
|
<line num="162" type="method" name="method_2" count="3"/> |
124
|
|
|
<line num="164" type="stmt" count="3"/> |
125
|
|
|
<line num="165" type="stmt" count="3"/> |
126
|
|
|
</file> |
127
|
|
|
</project> |
128
|
|
|
</coverage> |
129
|
|
|
HERE; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* (non-PHPDoc) |
133
|
|
|
* |
134
|
|
|
* @see tests/cbAbstractTests#setUp() |
135
|
|
|
*/ |
136
|
|
|
protected function setUp(): void |
137
|
|
|
{ |
138
|
|
|
parent::setUp(); |
139
|
|
|
$issueXML = new IssueXML(); |
140
|
|
|
$xml = new DOMDocument('1.0', 'UTF-8'); |
141
|
|
|
$xml->loadXML($this->testXml); |
142
|
|
|
$issueXML->addXMLFile($xml); |
143
|
|
|
$this->errorCrap = new ErrorCRAP($issueXML); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Test getFileList |
148
|
|
|
* |
149
|
|
|
* @return void |
150
|
|
|
*/ |
151
|
|
|
public function testGettingFileList(): void |
152
|
|
|
{ |
153
|
|
|
$expected = [ |
154
|
|
|
new File( |
155
|
|
|
'/test/file', |
156
|
|
|
[ |
157
|
|
|
new Issue( |
158
|
|
|
'/test/file', |
159
|
|
|
143, |
160
|
|
|
143, |
161
|
|
|
'CRAP', |
162
|
|
|
'1', |
163
|
|
|
'Notice' |
164
|
|
|
), |
165
|
|
|
new Issue( |
166
|
|
|
'/test/file', |
167
|
|
|
162, |
168
|
|
|
162, |
169
|
|
|
'CRAP', |
170
|
|
|
'100', |
171
|
|
|
'Error' |
172
|
|
|
), |
173
|
|
|
] |
174
|
|
|
), |
175
|
|
|
new File( |
176
|
|
|
'/has/no/crap', |
177
|
|
|
[] |
178
|
|
|
), |
179
|
|
|
]; |
180
|
|
|
$actual = $this->errorCrap->getFileList(); |
181
|
|
|
static::assertEquals($expected, $actual); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Test getFileList with limit set |
186
|
|
|
* |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function testGetFileListWithLimit(): void |
190
|
|
|
{ |
191
|
|
|
$issueXML = new IssueXML(); |
192
|
|
|
$xml = new DOMDocument('1.0', 'UTF-8'); |
193
|
|
|
$xml->loadXML($this->testXml); |
194
|
|
|
$issueXML->addXMLFile($xml); |
195
|
|
|
$this->errorCrap = new ErrorCRAP( |
196
|
|
|
$issueXML, |
197
|
|
|
['threshold' => 30] |
198
|
|
|
); |
199
|
|
|
|
200
|
|
|
$expected = [ |
201
|
|
|
new File( |
202
|
|
|
'/test/file', |
203
|
|
|
[ |
204
|
|
|
new Issue( |
205
|
|
|
'/test/file', |
206
|
|
|
162, |
207
|
|
|
162, |
208
|
|
|
'CRAP', |
209
|
|
|
'100', |
210
|
|
|
'Error' |
211
|
|
|
), |
212
|
|
|
] |
213
|
|
|
), |
214
|
|
|
new File( |
215
|
|
|
'/has/no/crap', |
216
|
|
|
[] |
217
|
|
|
), |
218
|
|
|
]; |
219
|
|
|
$actual = $this->errorCrap->getFileList(); |
220
|
|
|
static::assertEquals($expected, $actual); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|