| 2 |
2 |
<?xml version="1.0" encoding="UTF-8"?> |
| 3 |
|
-<metrics ahh="0" andc="0" calls="30" ccn="21" classes="3" cloc="217" clsa="0" clsc="3" fanout="31" files="4" functions="2" interfs="2" leafs="3" loc="336" locExecutable="101" maxdit="0" ncloc="119" nom="6" nop="1" roots="0"> |
| 4 |
|
- <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/class.php" classes="2" cloc="84" functions="0" loc="128" locExecutable="36" ncloc="44"> |
| 5 |
|
- <class name="MyCouplingClass" cis="8" cloc="46" cr="0.15" csz="11" dit="0" impl="0" loc="82" locExecutable="30" ncloc="36" nom="2" rcr="0.15" vars="4" varsi="4" varsnp="1" wmc="7" wmci="7" wmcnp="7"> |
| 6 |
|
- <method name="removeItemAt" ccn="3" cloc="0" loc="10" locExecutable="9" ncloc="10"/> |
| 7 |
|
- <method name="getItemAt" ccn="4" cloc="0" loc="14" locExecutable="13" ncloc="14"/> |
|
3 |
+<metrics ahh="0" andc="0" calls="30" ccn="21" classes="3" cloc="217" clsa="0" clsc="3" fanout="31" files="4" functions="2" interfs="2" leafs="3" lloc="57" loc="336" locExecutable="101" maxdit="0" ncloc="119" nom="6" nop="1" roots="0"> |
|
4 |
+ <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/testPHPUnitLoggerResult/class.php" classes="2" cloc="84" functions="0" lloc="21" loc="128" locExecutable="36" ncloc="44"> |
|
5 |
+ <class name="MyCouplingClass" cis="8" cloc="46" cr="0.15" csz="11" dit="0" impl="0" lloc="13" loc="82" locExecutable="22" ncloc="36" noam="0" nocc="0" nom="2" noom="0" rcr="0.15" vars="4" varsi="4" varsnp="1" wmc="7" wmci="7" wmcnp="7"> |
|
6 |
+ <method name="removeItemAt" ccn="3" cloc="0" lloc="5" loc="10" locExecutable="9" ncloc="10"/> |
|
7 |
+ <method name="getItemAt" ccn="4" cloc="0" lloc="8" loc="14" locExecutable="13" ncloc="14"/> |
| 8 |
8 |
</class> |
| 9 |
|
- <class name="MyCouplingInterface" cloc="13" cr="0.15" loc="17" locExecutable="3" ncloc="4" nom="1" rcr="0.15"> |
| 10 |
|
- <method name="removeItemAt" cloc="0" loc="1" locExecutable="0" ncloc="1"/> |
|
9 |
+ <class name="MyCouplingInterface" cloc="13" cr="0.15" lloc="0" loc="17" locExecutable="0" ncloc="4" nom="1" rcr="0.15"> |
|
10 |
+ <method name="removeItemAt" cloc="0" lloc="0" loc="1" locExecutable="0" ncloc="1"/> |
| 11 |
11 |
</class> |
| 12 |
12 |
</file> |
| 13 |
|
- <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/method.php" classes="2" cloc="64" functions="0" loc="100" locExecutable="32" ncloc="36"> |
| 14 |
|
- <class name="MyMethodCouplingClass" cis="7" cloc="26" cr="0.15" csz="7" dit="0" impl="0" loc="54" locExecutable="26" ncloc="28" nom="2" rcr="0.15" vars="0" varsi="0" varsnp="0" wmc="7" wmci="7" wmcnp="7"> |
| 15 |
|
- <method name="getItemAt" ccn="4" cloc="0" loc="14" locExecutable="13" ncloc="14"/> |
| 16 |
|
- <method name="removeItemAt" ccn="3" cloc="0" loc="10" locExecutable="9" ncloc="10"/> |
|
13 |
+ <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/testPHPUnitLoggerResult/method.php" classes="2" cloc="64" functions="0" lloc="17" loc="100" locExecutable="32" ncloc="36"> |
|
14 |
+ <class name="MyMethodCouplingClass" cis="7" cloc="26" cr="0.15" csz="7" dit="0" impl="0" lloc="13" loc="54" locExecutable="22" ncloc="28" noam="0" nocc="0" nom="2" noom="0" rcr="0.15" vars="0" varsi="0" varsnp="0" wmc="7" wmci="7" wmcnp="7"> |
|
15 |
+ <method name="getItemAt" ccn="4" cloc="0" lloc="8" loc="14" locExecutable="13" ncloc="14"/> |
|
16 |
+ <method name="removeItemAt" ccn="3" cloc="0" lloc="5" loc="10" locExecutable="9" ncloc="10"/> |
| 17 |
17 |
</class> |
| 18 |
|
- <class name="MyMethodCouplingInterface" cloc="13" cr="0.15" loc="17" locExecutable="3" ncloc="4" nom="1" rcr="0.15"> |
| 19 |
|
- <method name="removeItemAt" cloc="0" loc="1" locExecutable="0" ncloc="1"/> |
|
18 |
+ <class name="MyMethodCouplingInterface" cloc="13" cr="0.15" lloc="0" loc="17" locExecutable="0" ncloc="4" nom="1" rcr="0.15"> |
|
19 |
+ <method name="removeItemAt" cloc="0" lloc="0" loc="1" locExecutable="0" ncloc="1"/> |
| 20 |
20 |
</class> |
| 21 |
21 |
</file> |
| 22 |
|
- <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/property.php" classes="1" cloc="36" functions="0" loc="48" locExecutable="8" ncloc="12"> |
| 23 |
|
- <class name="MyPropertyCouplingClass" cis="1" cloc="20" cr="0.15" csz="4" dit="0" impl="0" loc="30" locExecutable="6" ncloc="10" nom="0" rcr="0.15" vars="4" varsi="4" varsnp="1" wmc="0" wmci="0" wmcnp="0"/> |
|
22 |
+ <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/testPHPUnitLoggerResult/property.php" classes="1" cloc="36" functions="0" lloc="4" loc="48" locExecutable="8" ncloc="12"> |
|
23 |
+ <class name="MyPropertyCouplingClass" cis="1" cloc="20" cr="0.15" csz="4" dit="0" impl="0" lloc="0" loc="30" locExecutable="0" ncloc="10" noam="0" nocc="0" nom="0" noom="0" rcr="0.15" vars="4" varsi="4" varsnp="1" wmc="0" wmci="0" wmcnp="0"/> |
| 24 |
24 |
</file> |
| 25 |
|
- <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/function.php" classes="0" cloc="33" functions="2" loc="60" locExecutable="25" ncloc="27"> |
| 26 |
|
- <function name="getItemAt" ccn="4" cloc="0" loc="14" locExecutable="13" ncloc="14"/> |
| 27 |
|
- <function name="removeItemAt" ccn="3" cloc="0" loc="10" locExecutable="9" ncloc="10"/> |
|
25 |
+ <file name="/home/manu/Desktop/Projects/workspace.xplib.de/PHP_Depend/trunk/tests/PHP/Depend/_code/log/phpunit/testPHPUnitLoggerResult/function.php" classes="0" cloc="33" functions="2" lloc="15" loc="60" locExecutable="25" ncloc="27"> |
|
26 |
+ <function name="getItemAt" ccn="4" cloc="0" lloc="8" loc="14" locExecutable="13" ncloc="14"/> |
|
27 |
+ <function name="removeItemAt" ccn="3" cloc="0" lloc="5" loc="10" locExecutable="9" ncloc="10"/> |
| 28 |
28 |
</file> |
| 29 |
29 |
</metrics> |
| 113 |
165 |
* Tests that the logger generates an image file. |
| 114 |
166 |
* |
| 115 |
167 |
* @return void |
|
168 |
+ * @covers PHP_Depend_Log_Jdepend_Chart |
|
169 |
+ * @group pdepend |
|
170 |
+ * @group pdepend::log |
|
171 |
+ * @group pdepend::log::jdepend |
|
172 |
+ * @group unittest |
| 116 |
173 |
*/ |
| 117 |
174 |
public function testGeneratesCorrectSVGImageFile() |
| 118 |
175 |
{ |
| 119 |
|
- $fileName = self::createRunResourceURI('jdepend-test-out.svg'); |
| 120 |
|
- if (file_exists($fileName)) { |
| 121 |
|
- @unlink($fileName); |
| 122 |
|
- } |
|
176 |
+ $nodes = new PHP_Depend_Code_NodeIterator($this->_createPackages(true, true)); |
| 123 |
177 |
|
| 124 |
|
- $nodes = new PHP_Depend_Code_NodeIterator(array( |
| 125 |
|
- new PHP_Depend_Code_Package('packageA'), |
| 126 |
|
- new PHP_Depend_Code_Package('packageB') |
| 127 |
|
- )); |
|
178 |
+ $analyzer = new PHP_Depend_Metrics_Dependency_Analyzer(); |
|
179 |
+ $analyzer->analyze($nodes); |
| 128 |
180 |
|
|
181 |
+ $logger = new PHP_Depend_Log_Jdepend_Chart(); |
|
182 |
+ $logger->setLogFile($this->_outputFile); |
|
183 |
+ $logger->setCode($nodes); |
|
184 |
+ $logger->log($analyzer); |
|
185 |
+ $logger->close(); |
|
186 |
+ |
|
187 |
+ $this->assertFileExists($this->_outputFile); |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ /** |
|
191 |
+ * testGeneratedSvgImageContainsExpectedPackages |
|
192 |
+ * |
|
193 |
+ * @return void |
|
194 |
+ * @covers PHP_Depend_Log_Jdepend_Chart |
|
195 |
+ * @group pdepend |
|
196 |
+ * @group pdepend::log |
|
197 |
+ * @group pdepend::log::jdepend |
|
198 |
+ * @group unittest |
|
199 |
+ */ |
|
200 |
+ public function testGeneratedSvgImageContainsExpectedPackages() |
|
201 |
+ { |
|
202 |
+ $nodes = new PHP_Depend_Code_NodeIterator($this->_createPackages(true, true)); |
|
203 |
+ |
| 129 |
204 |
$analyzer = new PHP_Depend_Metrics_Dependency_Analyzer(); |
| 130 |
205 |
$analyzer->analyze($nodes); |
| 131 |
206 |
|
| 132 |
207 |
$logger = new PHP_Depend_Log_Jdepend_Chart(); |
| 133 |
|
- $logger->setLogFile($fileName); |
|
208 |
+ $logger->setLogFile($this->_outputFile); |
| 134 |
209 |
$logger->setCode($nodes); |
| 135 |
210 |
$logger->log($analyzer); |
|
211 |
+ $logger->close(); |
| 136 |
212 |
|
| 137 |
|
- $this->assertFileNotExists($fileName); |
|
213 |
+ $svg = new DOMDocument(); |
|
214 |
+ $svg->load($this->_outputFile); |
|
215 |
+ |
|
216 |
+ $xpath = new DOMXPath($svg); |
|
217 |
+ $xpath->registerNamespace('s', 'http://www.w3.org/2000/svg'); |
|
218 |
+ |
|
219 |
+ $this->assertEquals(1, $xpath->query("//s:ellipse[@title='package0']")->length); |
|
220 |
+ $this->assertEquals(1, $xpath->query("//s:ellipse[@title='package1']")->length); |
|
221 |
+ } |
|
222 |
+ |
|
223 |
+ /** |
|
224 |
+ * testGeneratesSVGImageDoesNotContainNoneUserDefinedPackages |
|
225 |
+ * |
|
226 |
+ * @return void |
|
227 |
+ * @covers PHP_Depend_Log_Jdepend_Chart |
|
228 |
+ * @group pdepend |
|
229 |
+ * @group pdepend::log |
|
230 |
+ * @group pdepend::log::jdepend |
|
231 |
+ * @group unittest |
|
232 |
+ */ |
|
233 |
+ public function testGeneratesSVGImageDoesNotContainNoneUserDefinedPackages() |
|
234 |
+ { |
|
235 |
+ $nodes = new PHP_Depend_Code_NodeIterator($this->_createPackages(true, false, true)); |
|
236 |
+ |
|
237 |
+ $analyzer = new PHP_Depend_Metrics_Dependency_Analyzer(); |
|
238 |
+ $analyzer->analyze($nodes); |
|
239 |
+ |
|
240 |
+ $logger = new PHP_Depend_Log_Jdepend_Chart(); |
|
241 |
+ $logger->setLogFile($this->_outputFile); |
|
242 |
+ $logger->setCode($nodes); |
|
243 |
+ $logger->log($analyzer); |
| 138 |
244 |
$logger->close(); |
| 139 |
|
- $this->assertFileExists($fileName); |
| 140 |
245 |
|
| 141 |
246 |
$svg = new DOMDocument(); |
| 142 |
|
- $svg->load($fileName); |
|
247 |
+ $svg->load($this->_outputFile); |
| 143 |
248 |
|
| 144 |
249 |
$xpath = new DOMXPath($svg); |
| 145 |
250 |
$xpath->registerNamespace('s', 'http://www.w3.org/2000/svg'); |
| 146 |
251 |
|
| 147 |
|
- $this->assertEquals(1, $xpath->query("//s:ellipse[@title='packageA']")->length); |
| 148 |
|
- $this->assertEquals(1, $xpath->query("//s:ellipse[@title='packageB']")->length); |
| 149 |
|
- |
| 150 |
|
- unlink($fileName); |
|
252 |
+ $this->assertEquals(0, $xpath->query("//s:ellipse[@title='package1']")->length); |
| 151 |
253 |
} |
| 152 |
254 |
|
|
255 |
+ /** |
|
256 |
+ * testCalculateCorrectEllipseSize |
|
257 |
+ * |
|
258 |
+ * @return void |
|
259 |
+ * @covers PHP_Depend_Log_Jdepend_Chart |
|
260 |
+ * @group pdepend |
|
261 |
+ * @group pdepend::log |
|
262 |
+ * @group pdepend::log::jdepend |
|
263 |
+ * @group unittest |
|
264 |
+ */ |
| 153 |
265 |
public function testCalculateCorrectEllipseSize() |
| 154 |
266 |
{ |
| 155 |
|
- $fileName = self::createRunResourceURI('jdepend-test-out.svg'); |
| 156 |
|
- if (file_exists($fileName)) { |
| 157 |
|
- @unlink($fileName); |
| 158 |
|
- } |
|
267 |
+ $nodes = $this->_createPackages(true, true); |
| 159 |
268 |
|
| 160 |
|
- $nodes = array( |
| 161 |
|
- new PHP_Depend_Code_Package('packageA'), |
| 162 |
|
- new PHP_Depend_Code_Package('packageB') |
| 163 |
|
- ); |
| 164 |
|
- |
| 165 |
269 |
$analyzer = new PHP_Depend_Log_Jdepend_DependencyAnalyzer(); |
| 166 |
270 |
$analyzer->stats = array( |
| 167 |
271 |
$nodes[0]->getUUID() => array( |
| 183 |
287 |
$nodes = new PHP_Depend_Code_NodeIterator($nodes); |
| 184 |
288 |
|
| 185 |
289 |
$logger = new PHP_Depend_Log_Jdepend_Chart(); |
| 186 |
|
- $logger->setLogFile($fileName); |
|
290 |
+ $logger->setLogFile($this->_outputFile); |
| 187 |
291 |
$logger->setCode($nodes); |
| 188 |
292 |
$logger->log($analyzer); |
| 189 |
293 |
|
| 190 |
|
- $this->assertFileNotExists($fileName); |
| 191 |
294 |
$logger->close(); |
| 192 |
|
- $this->assertFileExists($fileName); |
| 193 |
295 |
|
| 194 |
296 |
$svg = new DOMDocument(); |
| 195 |
|
- $svg->load($fileName); |
|
297 |
+ $svg->load($this->_outputFile); |
| 196 |
298 |
|
| 197 |
299 |
$xpath = new DOMXPath($svg); |
| 198 |
300 |
$xpath->registerNamespace('s', 'http://www.w3.org/2000/svg'); |
| 199 |
301 |
|
| 200 |
|
- $ellipseA = $xpath->query("//s:ellipse[@title='packageA']")->item(0); |
|
302 |
+ $ellipseA = $xpath->query("//s:ellipse[@title='package0']")->item(0); |
| 201 |
303 |
$matrixA = $ellipseA->getAttribute('transform'); |
| 202 |
304 |
preg_match('/matrix\(([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)\)/', $matrixA, $matches); |
| 203 |
305 |
$this->assertEquals(1, $matches[1]); |
| 204 |
306 |
$this->assertEquals(1, $matches[4]); |
| 205 |
307 |
|
| 206 |
|
- $ellipseB = $xpath->query("//s:ellipse[@title='packageB']")->item(0); |
|
308 |
+ $ellipseB = $xpath->query("//s:ellipse[@title='package1']")->item(0); |
| 207 |
309 |
$matrixB = $ellipseB->getAttribute('transform'); |
| 208 |
310 |
preg_match('/matrix\(([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)\)/', $matrixB, $matches); |
| 209 |
311 |
$this->assertEquals(0.3333333, $matches[1], null, 0.000001); |
| 210 |
312 |
$this->assertEquals(0.3333333, $matches[4], null, 0.000001); |
| 211 |
|
- |
| 212 |
|
- unlink($fileName); |
| 213 |
313 |
} |
| 214 |
314 |
|
| 215 |
315 |
/** |
| 216 |
316 |
* Tests that the logger generates an image file. |
| 217 |
317 |
* |
| 218 |
318 |
* @return void |
|
319 |
+ * @covers PHP_Depend_Log_Jdepend_Chart |
|
320 |
+ * @group pdepend |
|
321 |
+ * @group pdepend::log |
|
322 |
+ * @group pdepend::log::jdepend |
|
323 |
+ * @group unittest |
| 219 |
324 |
*/ |
| 220 |
325 |
public function testGeneratesImageFile() |
| 221 |
326 |
{ |
| 191 |
227 |
$log = new PHP_Depend_Log_Summary_Xml(); |
| 192 |
228 |
$log->setLogFile($this->resultFile); |
| 193 |
229 |
$log->setCode(new PHP_Depend_Code_NodeIterator(array())); |
| 194 |
|
- $this->assertTrue($log->log($resultOne)); |
| 195 |
|
- $this->assertTrue($log->log($resultTwo)); |
|
230 |
+ $log->log($resultOne); |
|
231 |
+ $log->log($resultTwo); |
| 196 |
232 |
|
| 197 |
233 |
$log->close(); |
| 198 |
234 |
|
| 199 |
235 |
$fileName = 'project-aware-result-set-without-code.xml'; |
| 200 |
236 |
$this->assertXmlStringEqualsXmlString( |
| 201 |
237 |
$this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"), |
| 202 |
|
- file_get_contents($this->resultFile) |
|
238 |
+ $this->getNormalizedPathXml($this->resultFile) |
| 203 |
239 |
); |
| 204 |
240 |
} |
| 205 |
241 |
|
|
242 |
+ /** |
|
243 |
+ * testAnalyzersThatImplementProjectAndNodeAwareAsExpected |
|
244 |
+ * |
|
245 |
+ * @return void |
|
246 |
+ * @covers PHP_Depend_Log_Summary_Xml |
|
247 |
+ * @group pdepend |
|
248 |
+ * @group pdepend::log |
|
249 |
+ * @group pdepend::log::summary |
|
250 |
+ * @group unittest |
|
251 |
+ */ |
|
252 |
+ public function testAnalyzersThatImplementProjectAndNodeAwareAsExpected() |
|
253 |
+ { |
|
254 |
+ $analyzer = new PHP_Depend_Log_Summary_AnalyzerNodeAndProjectAwareDummy( |
|
255 |
+ array('foo' => 42, 'bar' => 23), |
|
256 |
+ array('baz' => 23, 'foobar' => 42) |
|
257 |
+ ); |
|
258 |
+ |
|
259 |
+ $log = new PHP_Depend_Log_Summary_Xml(); |
|
260 |
+ $log->setLogFile($this->resultFile); |
|
261 |
+ $log->setCode($this->packages); |
|
262 |
+ $log->log($analyzer); |
|
263 |
+ |
|
264 |
+ $log->close(); |
|
265 |
+ |
|
266 |
+ $fileName = 'node-and-project-aware-result-set.xml'; |
|
267 |
+ $this->assertXmlStringEqualsXmlString( |
|
268 |
+ $this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"), |
|
269 |
+ $this->getNormalizedPathXml($this->resultFile) |
|
270 |
+ ); |
|
271 |
+ } |
|
272 |
+ |
| 206 |
273 |
public function testNodeAwareAnalyzer() |
| 207 |
274 |
{ |
| 208 |
275 |
$input = array( |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category QualityAssurance |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Log |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once 'PHP/Depend/Metrics/AnalyzerI.php'; |
|
51 |
+require_once 'PHP/Depend/Metrics/NodeAwareI.php'; |
|
52 |
+require_once 'PHP/Depend/Metrics/ProjectAwareI.php'; |
|
53 |
+ |
|
54 |
+/** |
|
55 |
+ * Dummy implementation of an analyzer. |
|
56 |
+ * |
|
57 |
+ * @category QualityAssurance |
|
58 |
+ * @package PHP_Depend |
|
59 |
+ * @subpackage Log |
|
60 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
61 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
62 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
63 |
+ * @version Release: @package_version@ |
|
64 |
+ * @link http://pdepend.org/ |
|
65 |
+ */ |
|
66 |
+class PHP_Depend_Log_Summary_AnalyzerNodeAndProjectAwareDummy |
|
67 |
+ implements PHP_Depend_Metrics_AnalyzerI, |
|
68 |
+ PHP_Depend_Metrics_NodeAwareI, |
|
69 |
+ PHP_Depend_Metrics_ProjectAwareI |
|
70 |
+{ |
|
71 |
+ /** |
|
72 |
+ * Dummy project metrics. |
|
73 |
+ * |
|
74 |
+ * @var array(string=>mixed) $projectMetrics |
|
75 |
+ */ |
|
76 |
+ protected $projectMetrics = null; |
|
77 |
+ |
|
78 |
+ /** |
|
79 |
+ * Dummy node metrics. |
|
80 |
+ * |
|
81 |
+ * @var array(string=>array) $nodeMetrics |
|
82 |
+ */ |
|
83 |
+ protected $nodeMetrics = null; |
|
84 |
+ |
|
85 |
+ /** |
|
86 |
+ * Constructs a new analyzer dummy instance. |
|
87 |
+ * |
|
88 |
+ * @param array(string=>mixed) $projectMetrics Dummy project metrics. |
|
89 |
+ * @param array(string=>array) $nodeMetrics Dummy node metrics. |
|
90 |
+ */ |
|
91 |
+ public function __construct(array $projectMetrics = array(), array $nodeMetrics = array()) |
|
92 |
+ { |
|
93 |
+ $this->projectMetrics = $projectMetrics; |
|
94 |
+ $this->nodeMetrics = $nodeMetrics; |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ /** |
|
98 |
+ * Adds a listener to this analyzer. |
|
99 |
+ * |
|
100 |
+ * @param PHP_Depend_Metrics_ListenerI $listener The listener instance. |
|
101 |
+ * |
|
102 |
+ * @return void |
|
103 |
+ */ |
|
104 |
+ public function addAnalyzeListener(PHP_Depend_Metrics_ListenerI $listener) { |
|
105 |
+ } |
|
106 |
+ |
|
107 |
+ /** |
|
108 |
+ * Removes the listener from this analyzer. |
|
109 |
+ * |
|
110 |
+ * @param PHP_Depend_Metrics_ListenerI $listener The listener instance. |
|
111 |
+ * |
|
112 |
+ * @return void |
|
113 |
+ */ |
|
114 |
+ public function removeAnalyzeListener(PHP_Depend_Metrics_ListenerI $listener) { |
|
115 |
+ } |
|
116 |
+ |
|
117 |
+ /** |
|
118 |
+ * Processes all {@link PHP_Depend_Code_Package} code nodes. |
|
119 |
+ * |
|
120 |
+ * @param PHP_Depend_Code_NodeIterator $packages All code packages. |
|
121 |
+ * |
|
122 |
+ * @return void |
|
123 |
+ */ |
|
124 |
+ public function analyze(PHP_Depend_Code_NodeIterator $packages) |
|
125 |
+ { |
|
126 |
+ } |
|
127 |
+ |
|
128 |
+ /** |
|
129 |
+ * By default all analyzers are enabled. Overwrite this method to provide |
|
130 |
+ * state based disabling/enabling. |
|
131 |
+ * |
|
132 |
+ * @return boolean |
|
133 |
+ * @since 0.9.10 |
|
134 |
+ */ |
|
135 |
+ public function isEnabled() |
|
136 |
+ { |
|
137 |
+ return true; |
|
138 |
+ } |
|
139 |
+ |
|
140 |
+ /** |
|
141 |
+ * Returns the project metrics. |
|
142 |
+ * |
|
143 |
+ * @return array(string=>mixed) |
|
144 |
+ * @see PHP_Depend_Metrics_ProjectAwareI::getProjectMetrics() |
|
145 |
+ */ |
|
146 |
+ public function getProjectMetrics() |
|
147 |
+ { |
|
148 |
+ return $this->projectMetrics; |
|
149 |
+ } |
|
150 |
+ |
|
151 |
+ /** |
|
152 |
+ * Returns an array with metrics for the requested node. |
|
153 |
+ * |
|
154 |
+ * @param PHP_Depend_Code_NodeI $node The context node instance. |
|
155 |
+ * |
|
156 |
+ * @return array(string=>mixed) |
|
157 |
+ * @see PHP_Depend_Metrics_NodeAwareI::getNodeMetrics() |
|
158 |
+ */ |
|
159 |
+ public function getNodeMetrics(PHP_Depend_Code_NodeI $node) |
|
160 |
+ { |
|
161 |
+ return $this->nodeMetrics; |
|
162 |
+ } |
|
163 |
+} |
| 1227 |
1280 |
} |
| 1228 |
1281 |
|
| 1229 |
1282 |
/** |
|
1283 |
+ * testParserStripsLeadingSlashFromNamespacedClassName |
|
1284 |
+ * |
|
1285 |
+ * @return void |
|
1286 |
+ * @covers PHP_Depend_Parser::_getNamespaceOrPackageName |
|
1287 |
+ * @group pdepend |
|
1288 |
+ * @group pdepend::parser |
|
1289 |
+ * @group unittest |
|
1290 |
+ */ |
|
1291 |
+ public function testParserStripsLeadingSlashFromNamespacedClassName() |
|
1292 |
+ { |
|
1293 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1294 |
+ $package = $packages->current(); |
|
1295 |
+ |
|
1296 |
+ $this->assertEquals('foo', $package->getName()); |
|
1297 |
+ } |
|
1298 |
+ |
|
1299 |
+ /** |
|
1300 |
+ * testParserStripsLeadingSlashFromNamespacedClassName |
|
1301 |
+ * |
|
1302 |
+ * @return void |
|
1303 |
+ * @covers PHP_Depend_Parser::_getNamespaceOrPackageName |
|
1304 |
+ * @group pdepend |
|
1305 |
+ * @group pdepend::parser |
|
1306 |
+ * @group unittest |
|
1307 |
+ */ |
|
1308 |
+ public function testParserStripsLeadingSlashFromNamespaceAliasedClassName() |
|
1309 |
+ { |
|
1310 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1311 |
+ $package = $packages->current() |
|
1312 |
+ ->getClasses() |
|
1313 |
+ ->current() |
|
1314 |
+ ->getParentClass() |
|
1315 |
+ ->getPackage(); |
|
1316 |
+ |
|
1317 |
+ $this->assertEquals('foo\bar\baz', $package->getName()); |
|
1318 |
+ } |
|
1319 |
+ |
|
1320 |
+ /** |
|
1321 |
+ * testParserStripsLeadingSlashFromInheritNamespacedClassName |
|
1322 |
+ * |
|
1323 |
+ * @return void |
|
1324 |
+ * @covers PHP_Depend_Parser::_parseQualifiedName |
|
1325 |
+ * @group pdepend |
|
1326 |
+ * @group pdepend::parser |
|
1327 |
+ * @group unittest |
|
1328 |
+ */ |
|
1329 |
+ public function testParserStripsLeadingSlashFromInheritNamespacedClassName() |
|
1330 |
+ { |
|
1331 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1332 |
+ $package = $packages->current() |
|
1333 |
+ ->getClasses() |
|
1334 |
+ ->current() |
|
1335 |
+ ->getParentClass() |
|
1336 |
+ ->getPackage(); |
|
1337 |
+ |
|
1338 |
+ $this->assertEquals('bar', $package->getName()); |
|
1339 |
+ } |
|
1340 |
+ |
|
1341 |
+ /** |
|
1342 |
+ * testParserThrowsExpectedExceptionWhenDefaultStaticDefaultValueNotExists |
|
1343 |
+ * |
|
1344 |
+ * @return void |
|
1345 |
+ * @covers PHP_Depend_Parser |
|
1346 |
+ * @group pdepend |
|
1347 |
+ * @group pdepend::parser |
|
1348 |
+ * @group unittest |
|
1349 |
+ * @expectedException PHP_Depend_Parser_MissingValueException |
|
1350 |
+ */ |
|
1351 |
+ public function testParserThrowsExpectedExceptionWhenDefaultStaticDefaultValueNotExists() |
|
1352 |
+ { |
|
1353 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1354 |
+ } |
|
1355 |
+ |
|
1356 |
+ /** |
|
1357 |
+ * testParserHandlesDoubleQuoteStringAsConstantDefaultValue |
|
1358 |
+ * |
|
1359 |
+ * @return void |
|
1360 |
+ * @covers PHP_Depend_Parser |
|
1361 |
+ * @group pdepend |
|
1362 |
+ * @group pdepend::parser |
|
1363 |
+ * @group unittest |
|
1364 |
+ */ |
|
1365 |
+ public function testParserHandlesDoubleQuoteStringAsConstantDefaultValue() |
|
1366 |
+ { |
|
1367 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1368 |
+ } |
|
1369 |
+ |
|
1370 |
+ /** |
|
1371 |
+ * testParserHandlesDoubleQuoteStringWithEscapedVariable |
|
1372 |
+ * |
|
1373 |
+ * @return void |
|
1374 |
+ * @covers PHP_Depend_Parser |
|
1375 |
+ * @group pdepend |
|
1376 |
+ * @group pdepend::parser |
|
1377 |
+ * @group unittest |
|
1378 |
+ */ |
|
1379 |
+ public function testParserHandlesDoubleQuoteStringWithEscapedVariable() |
|
1380 |
+ { |
|
1381 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1382 |
+ $function = $packages->current() |
|
1383 |
+ ->getFunctions() |
|
1384 |
+ ->current(); |
|
1385 |
+ |
|
1386 |
+ $string = $function->getFirstChildOfType(PHP_Depend_Code_ASTString::CLAZZ); |
|
1387 |
+ $image = $string->getChild(0)->getImage(); |
|
1388 |
+ |
|
1389 |
+ $this->assertEquals('\$foobar', $image); |
|
1390 |
+ } |
|
1391 |
+ |
|
1392 |
+ /** |
|
1393 |
+ * testParserHandlesDoubleQuoteStringWithEscapedDoubleQuote |
|
1394 |
+ * |
|
1395 |
+ * @return void |
|
1396 |
+ * @covers PHP_Depend_Parser |
|
1397 |
+ * @group pdepend |
|
1398 |
+ * @group pdepend::parser |
|
1399 |
+ * @group unittest |
|
1400 |
+ */ |
|
1401 |
+ public function testParserHandlesDoubleQuoteStringWithEscapedDoubleQuote() |
|
1402 |
+ { |
|
1403 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1404 |
+ $function = $packages->current() |
|
1405 |
+ ->getFunctions() |
|
1406 |
+ ->current(); |
|
1407 |
+ |
|
1408 |
+ $string = $function->getFirstChildOfType(PHP_Depend_Code_ASTString::CLAZZ); |
|
1409 |
+ $image = $string->getChild(0)->getImage(); |
|
1410 |
+ |
|
1411 |
+ $this->assertEquals('\\\\\"', $image); |
|
1412 |
+ } |
|
1413 |
+ |
|
1414 |
+ /** |
|
1415 |
+ * testParserNotHandlesDoubleQuoteStringWithVariableAndParenthesisAsFunctionCall |
|
1416 |
+ * |
|
1417 |
+ * @return void |
|
1418 |
+ * @covers PHP_Depend_Parser |
|
1419 |
+ * @group pdepend |
|
1420 |
+ * @group pdepend::parser |
|
1421 |
+ * @group unittest |
|
1422 |
+ */ |
|
1423 |
+ public function testParserNotHandlesDoubleQuoteStringWithVariableAndParenthesisAsFunctionCall() |
|
1424 |
+ { |
|
1425 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1426 |
+ $function = $packages->current() |
|
1427 |
+ ->getFunctions() |
|
1428 |
+ ->current(); |
|
1429 |
+ |
|
1430 |
+ $string = $function->getFirstChildOfType(PHP_Depend_Code_ASTString::CLAZZ); |
|
1431 |
+ $variable = $string->getChild(0); |
|
1432 |
+ |
|
1433 |
+ $this->assertType(PHP_Depend_Code_ASTVariable::CLAZZ, $variable); |
|
1434 |
+ } |
|
1435 |
+ |
|
1436 |
+ /** |
|
1437 |
+ * testParserNotHandlesDoubleQuoteStringWithVariableAndEqualAsAssignment |
|
1438 |
+ * |
|
1439 |
+ * @return void |
|
1440 |
+ * @covers PHP_Depend_Parser |
|
1441 |
+ * @group pdepend |
|
1442 |
+ * @group pdepend::parser |
|
1443 |
+ * @group unittest |
|
1444 |
+ */ |
|
1445 |
+ public function testParserNotHandlesDoubleQuoteStringWithVariableAndEqualAsAssignment() |
|
1446 |
+ { |
|
1447 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1448 |
+ $function = $packages->current() |
|
1449 |
+ ->getFunctions() |
|
1450 |
+ ->current(); |
|
1451 |
+ |
|
1452 |
+ $string = $function->getFirstChildOfType(PHP_Depend_Code_ASTString::CLAZZ); |
|
1453 |
+ $variable = $string->getChild(0); |
|
1454 |
+ |
|
1455 |
+ $this->assertType(PHP_Depend_Code_ASTVariable::CLAZZ, $variable); |
|
1456 |
+ } |
|
1457 |
+ |
|
1458 |
+ /** |
|
1459 |
+ * testParserHandlesStringWithQuestionMarkNotAsTernaryOperator |
|
1460 |
+ * |
|
1461 |
+ * @return void |
|
1462 |
+ * @covers PHP_Depend_Parser |
|
1463 |
+ * @group pdepend |
|
1464 |
+ * @group pdepend::parser |
|
1465 |
+ * @group unittest |
|
1466 |
+ */ |
|
1467 |
+ public function testParserHandlesStringWithQuestionMarkNotAsTernaryOperator() |
|
1468 |
+ { |
|
1469 |
+ $packages = self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1470 |
+ $method = $packages->current() |
|
1471 |
+ ->getClasses() |
|
1472 |
+ ->current() |
|
1473 |
+ ->getMethods() |
|
1474 |
+ ->current(); |
|
1475 |
+ |
|
1476 |
+ $string = $method->getFirstChildOfType(PHP_Depend_Code_ASTString::CLAZZ); |
|
1477 |
+ $this->assertType(PHP_Depend_Code_ASTLiteral::CLAZZ, $string->getChild(1)); |
|
1478 |
+ } |
|
1479 |
+ |
|
1480 |
+ /** |
|
1481 |
+ * testParseClosureAsFunctionArgument |
|
1482 |
+ * |
|
1483 |
+ * @return void |
|
1484 |
+ * @covers PHP_Depend_Parser |
|
1485 |
+ * @group pdepend |
|
1486 |
+ * @group pdepend::parser |
|
1487 |
+ * @group unittest |
|
1488 |
+ */ |
|
1489 |
+ public function testParseClosureAsFunctionArgument() |
|
1490 |
+ { |
|
1491 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1492 |
+ } |
|
1493 |
+ |
|
1494 |
+ /** |
|
1495 |
+ * testParseNowdocInMethodBody |
|
1496 |
+ * |
|
1497 |
+ * @return void |
|
1498 |
+ * @covers PHP_Depend_Parser |
|
1499 |
+ * @group pdepend |
|
1500 |
+ * @group pdepend::parser |
|
1501 |
+ * @group unittest |
|
1502 |
+ */ |
|
1503 |
+ public function testParseNowdocInMethodBody() |
|
1504 |
+ { |
|
1505 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1506 |
+ } |
|
1507 |
+ |
|
1508 |
+ /** |
|
1509 |
+ * testParseDoWhileStatement |
|
1510 |
+ * |
|
1511 |
+ * @return void |
|
1512 |
+ * @covers PHP_Depend_Parser |
|
1513 |
+ * @group pdepend |
|
1514 |
+ * @group pdepend::parser |
|
1515 |
+ * @group unittest |
|
1516 |
+ */ |
|
1517 |
+ public function testParseDoWhileStatement() |
|
1518 |
+ { |
|
1519 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1520 |
+ } |
|
1521 |
+ |
|
1522 |
+ /** |
|
1523 |
+ * testParserHandlesCompoundExpressionInArrayBrackets |
|
1524 |
+ * |
|
1525 |
+ * @return void |
|
1526 |
+ * @covers PHP_Depend_Parser |
|
1527 |
+ * @group pdepend |
|
1528 |
+ * @group pdepend::parser |
|
1529 |
+ * @group unittest |
|
1530 |
+ */ |
|
1531 |
+ public function testParserHandlesCompoundExpressionInArrayBrackets() |
|
1532 |
+ { |
|
1533 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1534 |
+ } |
|
1535 |
+ |
|
1536 |
+ /** |
|
1537 |
+ * testParserHandlesEmptyNonePhpCodeInMethodBody |
|
1538 |
+ * |
|
1539 |
+ * @return void |
|
1540 |
+ * @covers PHP_Depend_Parser |
|
1541 |
+ * @group pdepend |
|
1542 |
+ * @group pdepend::parser |
|
1543 |
+ * @group unittest |
|
1544 |
+ */ |
|
1545 |
+ public function testParserHandlesEmptyNonePhpCodeInMethodBody() |
|
1546 |
+ { |
|
1547 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1548 |
+ } |
|
1549 |
+ |
|
1550 |
+ /** |
|
1551 |
+ * testParserHandlesPhpCloseTagInMethodBody |
|
1552 |
+ * |
|
1553 |
+ * @return void |
|
1554 |
+ * @covers PHP_Depend_Parser |
|
1555 |
+ * @group pdepend |
|
1556 |
+ * @group pdepend::parser |
|
1557 |
+ * @group unittest |
|
1558 |
+ */ |
|
1559 |
+ public function testParserHandlesPhpCloseTagInMethodBody() |
|
1560 |
+ { |
|
1561 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1562 |
+ } |
|
1563 |
+ |
|
1564 |
+ /** |
|
1565 |
+ * testParserHandlesMultiplePhpCloseTagsInMethodBody |
|
1566 |
+ * |
|
1567 |
+ * @return void |
|
1568 |
+ * @covers PHP_Depend_Parser |
|
1569 |
+ * @group pdepend |
|
1570 |
+ * @group pdepend::parser |
|
1571 |
+ * @group unittest |
|
1572 |
+ */ |
|
1573 |
+ public function testParserHandlesMultiplePhpCloseTagsInMethodBody() |
|
1574 |
+ { |
|
1575 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1576 |
+ } |
|
1577 |
+ |
|
1578 |
+ /** |
|
1579 |
+ * testParseExpressionUntilThrowsExceptionForUnclosedStatement |
|
1580 |
+ * |
|
1581 |
+ * @return void |
|
1582 |
+ * @covers PHP_Depend_Parser |
|
1583 |
+ * @group pdepend |
|
1584 |
+ * @group pdepend::parser |
|
1585 |
+ * @group unittest |
|
1586 |
+ * @expectedException PHP_Depend_Parser_UnexpectedTokenException |
|
1587 |
+ */ |
|
1588 |
+ public function testParseExpressionUntilThrowsExceptionForUnclosedStatement() |
|
1589 |
+ { |
|
1590 |
+ self::parseSource('parser/' . __FUNCTION__ . '.php'); |
|
1591 |
+ } |
|
1592 |
+ |
|
1593 |
+ /** |
| 1230 |
1594 |
* Tests that the parser ignores variable class instantiation. |
| 1231 |
1595 |
* |
| 1232 |
1596 |
* http://bugs.xplib.de/index.php?do=details&task_id=10&project=3 |
| 1774 |
2135 |
} |
| 1775 |
2136 |
|
| 1776 |
2137 |
/** |
| 1777 |
|
- * Tests that the parser recognizes a inline type definition within a comment. |
| 1778 |
|
- * Such a comment will look like: |
|
2138 |
+ * Parses the given source file or directory with the default tokenizer |
|
2139 |
+ * and node builder implementations. |
| 1779 |
2140 |
* |
| 1780 |
|
- * <code> |
| 1781 |
|
- * function foo() { |
| 1782 |
|
- * /* @var $bar Bar * / |
| 1783 |
|
- * $bar = bar(); |
| 1784 |
|
- * } |
| 1785 |
|
- * </code> |
| 1786 |
|
- */ |
| 1787 |
|
- public function testParserSetsDependencyDefinedInInlineCommentWithWhitespaceIssue87() |
| 1788 |
|
- { |
| 1789 |
|
- $packages = self::parseSource('issues/087-1.php'); |
| 1790 |
|
- $this->assertSame(1, $packages->count()); |
| 1791 |
|
- |
| 1792 |
|
- $function = $packages->current()->getFunctions()->current(); |
| 1793 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 1794 |
|
- |
| 1795 |
|
- $dependencies = $function->getDependencies(); |
| 1796 |
|
- $this->assertSame(1, $dependencies->count()); |
| 1797 |
|
- |
| 1798 |
|
- $type = $dependencies->current(); |
| 1799 |
|
- $this->assertSame('Bar', $type->getName()); |
| 1800 |
|
- } |
| 1801 |
|
- |
| 1802 |
|
- /** |
| 1803 |
|
- * Tests that the parser recognizes a inline type definition within a comment. |
| 1804 |
|
- * Such a comment will look like: |
|
2141 |
+ * @param string $testCase Qualified name of the test case. |
|
2142 |
+ * @param boolean $ignoreAnnotations The parser should ignore annotations. |
| 1805 |
2143 |
* |
| 1806 |
|
- * <code> |
| 1807 |
|
- * function foo() { |
| 1808 |
|
- * /*@var $bar Bar* / |
| 1809 |
|
- * $bar = bar(); |
| 1810 |
|
- * } |
| 1811 |
|
- * </code> |
|
2144 |
+ * @return PHP_Depend_Code_NodeIterator |
| 1812 |
2145 |
*/ |
| 1813 |
|
- public function testParserSetsDependencyDefinedInInlineCommentWithoutWhitespaceIssue87() |
|
2146 |
+ public static function parseTestCaseSource($testCase = null, $ignoreAnnotations = false) |
| 1814 |
2147 |
{ |
| 1815 |
|
- $packages = self::parseSource('issues/087-2.php'); |
| 1816 |
|
- $this->assertSame(1, $packages->count()); |
| 1817 |
|
- |
| 1818 |
|
- $function = $packages->current()->getFunctions()->current(); |
| 1819 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 1820 |
|
- |
| 1821 |
|
- $dependencies = $function->getDependencies(); |
| 1822 |
|
- $this->assertSame(1, $dependencies->count()); |
| 1823 |
|
- |
| 1824 |
|
- $type = $dependencies->current(); |
| 1825 |
|
- $this->assertSame('Bar', $type->getName()); |
|
2148 |
+ $trace = debug_backtrace(); |
|
2149 |
+ return self::parseSource('parser/' . $trace[1]['function'] . '.php'); |
| 1826 |
2150 |
} |
| 1827 |
2151 |
|
| 1828 |
2152 |
/** |
| 1829 |
|
- * Tests that the parser ignores a inline type definition within a multiline |
| 1830 |
|
- * comment. |
| 1831 |
|
- * Such a comment will look like: |
| 1832 |
|
- * |
| 1833 |
|
- * <code> |
| 1834 |
|
- * function foo() { |
| 1835 |
|
- * /* |
| 1836 |
|
- * * @var $bar Bar |
| 1837 |
|
- * * / |
| 1838 |
|
- * $bar = bar(); |
| 1839 |
|
- * } |
| 1840 |
|
- * </code> |
| 1841 |
|
- */ |
| 1842 |
|
- public function testParserIgnoresDependencyDefinedInMultilineCommentIssue87() |
| 1843 |
|
- { |
| 1844 |
|
- $packages = self::parseSource('issues/087-3.php'); |
| 1845 |
|
- $this->assertSame(1, $packages->count()); |
| 1846 |
|
- |
| 1847 |
|
- $function = $packages->current()->getFunctions()->current(); |
| 1848 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 1849 |
|
- |
| 1850 |
|
- $dependencies = $function->getDependencies(); |
| 1851 |
|
- $this->assertSame(0, $dependencies->count()); |
| 1852 |
|
- } |
| 1853 |
|
- |
| 1854 |
|
- /** |
| 1855 |
|
- * Tests that the parser ignores a inline type definition within a nested |
| 1856 |
|
- * comment. |
| 1857 |
|
- * Such a comment will look like: |
| 1858 |
|
- * |
| 1859 |
|
- * <code> |
| 1860 |
|
- * function foo() { |
| 1861 |
|
- * // A comment line... /* @var $bar Bar * / |
| 1862 |
|
- * $bar = bar(); |
| 1863 |
|
- * } |
| 1864 |
|
- * </code> |
| 1865 |
|
- */ |
| 1866 |
|
- public function testParserIgnoresDependencyDefinedWithinAnotherCommentIssue87() |
| 1867 |
|
- { |
| 1868 |
|
- $packages = self::parseSource('issues/087-4.php'); |
| 1869 |
|
- $this->assertSame(1, $packages->count()); |
| 1870 |
|
- |
| 1871 |
|
- $function = $packages->current()->getFunctions()->current(); |
| 1872 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 1873 |
|
- |
| 1874 |
|
- $dependencies = $function->getDependencies(); |
| 1875 |
|
- $this->assertSame(0, $dependencies->count()); |
| 1876 |
|
- } |
| 1877 |
|
- |
| 1878 |
|
- /** |
| 1879 |
2153 |
* Returns all packages in the mixed code example. |
| 1880 |
2154 |
* |
| 1881 |
2155 |
* @return PHP_Depend_Code_NodeIterator |
| 105 |
113 |
$runner->run(); |
| 106 |
114 |
} |
| 107 |
115 |
|
|
116 |
+ /** |
|
117 |
+ * testRunnerUsesCorrectFileFilter |
|
118 |
+ * |
|
119 |
+ * @return void |
|
120 |
+ * @covers PHP_Depend_TextUI_Runner |
|
121 |
+ * @group pdepend |
|
122 |
+ * @group pdepend::textui |
|
123 |
+ * @group unittest |
|
124 |
+ */ |
| 108 |
125 |
public function testRunnerUsesCorrectFileFilter() |
| 109 |
126 |
{ |
| 110 |
|
- $fileName = self::createRunResourceURI('pdepend.dummy'); |
| 111 |
|
- if (file_exists($fileName)) { |
| 112 |
|
- unlink($fileName); |
| 113 |
|
- } |
|
127 |
+ $expected = array( |
|
128 |
+ 'pdepend.test' => array( |
|
129 |
+ 'functions' => 1, |
|
130 |
+ 'classes' => 1, |
|
131 |
+ 'interfaces' => 0, |
|
132 |
+ 'exceptions' => 0 |
|
133 |
+ ), |
|
134 |
+ 'pdepend.test2' => array( |
|
135 |
+ 'functions' => 0, |
|
136 |
+ 'classes' => 1, |
|
137 |
+ 'interfaces' => 0, |
|
138 |
+ 'exceptions' => 0 |
|
139 |
+ ) |
|
140 |
+ ); |
| 114 |
141 |
|
| 115 |
142 |
$runner = new PHP_Depend_TextUI_Runner(); |
| 116 |
|
- $runner->setSourceArguments(array(dirname(__FILE__). '/../_code')); |
|
143 |
+ $runner->setWithoutAnnotations(); |
| 117 |
144 |
$runner->setFileExtensions(array('inc')); |
| 118 |
|
- $runner->addLogger('dummy-logger', $fileName); |
| 119 |
145 |
|
| 120 |
|
- ob_start(); |
| 121 |
|
- $runner->run(); |
| 122 |
|
- ob_end_clean(); |
|
146 |
+ $actual = $this->_runRunnerAndReturnStatistics( |
|
147 |
+ $runner, |
|
148 |
+ self::createCodeResourceURI('textui/Runner/' . __FUNCTION__) |
|
149 |
+ ); |
| 123 |
150 |
|
| 124 |
|
- $this->assertFileExists($fileName); |
| 125 |
|
- |
| 126 |
|
- $data = unserialize(file_get_contents($fileName)); |
| 127 |
|
- |
| 128 |
|
- $code = $data['code']; |
| 129 |
|
- $this->assertType('PHP_Depend_Code_NodeIterator', $code); |
| 130 |
|
- $this->assertEquals(2, $code->count()); |
| 131 |
|
- |
| 132 |
|
- $code->rewind(); |
| 133 |
|
- |
| 134 |
|
- $package = $code->current(); |
| 135 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 136 |
|
- $this->assertEquals('pdepend.test', $package->getName()); |
| 137 |
|
- |
| 138 |
|
- $this->assertEquals(1, $package->getFunctions()->count()); |
| 139 |
|
- $this->assertEquals(1, $package->getClasses()->count()); |
| 140 |
|
- |
| 141 |
|
- $function = $package->getFunctions()->current(); |
| 142 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 143 |
|
- $this->assertEquals('foo', $function->getName()); |
| 144 |
|
- $this->assertEquals(1, $function->getExceptionClasses()->count()); |
| 145 |
|
- $this->assertEquals('MyException', $function->getExceptionClasses()->current()->getName()); |
| 146 |
|
- |
| 147 |
|
- $code->next(); |
| 148 |
|
- |
| 149 |
|
- $package = $code->current(); |
| 150 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 151 |
|
- $this->assertEquals('pdepend.test2', $package->getName()); |
| 152 |
|
- |
| 153 |
|
- $sourceFile = realpath(dirname(__FILE__). '/../_code/function.inc'); |
| 154 |
|
- $this->assertEquals($sourceFile, $function->getSourceFile()->getName()); |
| 155 |
|
- |
| 156 |
|
- unlink($fileName); |
|
151 |
+ $this->assertEquals($expected, $actual); |
| 157 |
152 |
} |
| 158 |
153 |
|
| 159 |
154 |
/** |
| 161 |
156 |
* correct. |
| 162 |
157 |
* |
| 163 |
158 |
* @return void |
|
159 |
+ * @covers PHP_Depend_TextUI_Runner |
|
160 |
+ * @group pdepend |
|
161 |
+ * @group pdepend::textui |
|
162 |
+ * @group unittest |
| 164 |
163 |
*/ |
| 165 |
164 |
public function testRunnerHandlesWithoutAnnotationsOptionCorrect() |
| 166 |
165 |
{ |
| 167 |
|
- $fileName = self::createRunResourceURI('pdepend.dummy'); |
| 168 |
|
- if (file_exists($fileName)) { |
| 169 |
|
- unlink($fileName); |
| 170 |
|
- } |
|
166 |
+ $expected = array( |
|
167 |
+ 'pdepend.test' => array( |
|
168 |
+ 'functions' => 1, |
|
169 |
+ 'classes' => 1, |
|
170 |
+ 'interfaces' => 0, |
|
171 |
+ 'exceptions' => 0 |
|
172 |
+ ), |
|
173 |
+ 'pdepend.test2' => array( |
|
174 |
+ 'functions' => 0, |
|
175 |
+ 'classes' => 1, |
|
176 |
+ 'interfaces' => 0, |
|
177 |
+ 'exceptions' => 0 |
|
178 |
+ ) |
|
179 |
+ ); |
| 171 |
180 |
|
| 172 |
181 |
$runner = new PHP_Depend_TextUI_Runner(); |
| 173 |
|
- $runner->setSourceArguments(array(dirname(__FILE__). '/../_code')); |
| 174 |
|
- $runner->setFileExtensions(array('inc')); |
| 175 |
|
- $runner->addLogger('dummy-logger', $fileName); |
| 176 |
182 |
$runner->setWithoutAnnotations(); |
| 177 |
183 |
|
| 178 |
|
- ob_start(); |
| 179 |
|
- $runner->run(); |
| 180 |
|
- ob_end_clean(); |
|
184 |
+ $actual = $this->_runRunnerAndReturnStatistics( |
|
185 |
+ $runner, |
|
186 |
+ self::createCodeResourceURI('function.inc') |
|
187 |
+ ); |
| 181 |
188 |
|
| 182 |
|
- $this->assertFileExists($fileName); |
|
189 |
+ $this->assertEquals($expected, $actual); |
|
190 |
+ } |
| 183 |
191 |
|
| 184 |
|
- $data = unserialize(file_get_contents($fileName)); |
|
192 |
+ /** |
|
193 |
+ * testSupportBadDocumentation |
|
194 |
+ * |
|
195 |
+ * @return void |
|
196 |
+ * @covers PHP_Depend_TextUI_Runner |
|
197 |
+ * @group pdepend |
|
198 |
+ * @group pdepend::textui |
|
199 |
+ * @group unittest |
|
200 |
+ */ |
|
201 |
+ public function testSupportBadDocumentation() |
|
202 |
+ { |
|
203 |
+ $expected = array( |
|
204 |
+ '+global' => array( |
|
205 |
+ 'functions' => 1, |
|
206 |
+ 'classes' => 7, |
|
207 |
+ 'interfaces' => 3, |
|
208 |
+ 'exceptions' => 0 |
|
209 |
+ ) |
|
210 |
+ ); |
|
211 |
+ |
|
212 |
+ $runner = new PHP_Depend_TextUI_Runner(); |
|
213 |
+ $actual = $this->_runRunnerAndReturnStatistics( |
|
214 |
+ $runner, |
|
215 |
+ self::createCodeResourceURI('code-without-comments') |
|
216 |
+ ); |
| 185 |
217 |
|
| 186 |
|
- $code = $data['code']; |
| 187 |
|
- $this->assertType('PHP_Depend_Code_NodeIterator', $code); |
| 188 |
|
- $this->assertEquals(2, $code->count()); |
|
218 |
+ $this->assertEquals($expected, $actual); |
|
219 |
+ } |
| 189 |
220 |
|
| 190 |
|
- $code->rewind(); |
|
221 |
+ /** |
|
222 |
+ * testRunnerHasParseErrorsReturnsFalseForValidSource |
|
223 |
+ * |
|
224 |
+ * @return void |
|
225 |
+ * @covers PHP_Depend_TextUI_Runner |
|
226 |
+ * @group pdepend |
|
227 |
+ * @group pdepend::textui |
|
228 |
+ * @group unittest |
|
229 |
+ */ |
|
230 |
+ public function testRunnerHasParseErrorsReturnsFalseForValidSource() |
|
231 |
+ { |
|
232 |
+ $runner = new PHP_Depend_TextUI_Runner(); |
|
233 |
+ $runner->addLogger('dummy-logger', self::createRunResourceURI('pdepend.dummy')); |
|
234 |
+ $runner->setSourceArguments(array(self::createCodeResourceURI('textui/Runner/' . __FUNCTION__ . '.php'))); |
|
235 |
+ $runner->run(); |
| 191 |
236 |
|
| 192 |
|
- $package = $code->current(); |
| 193 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 194 |
|
- $this->assertEquals('pdepend.test', $package->getName()); |
|
237 |
+ $this->assertFalse($runner->hasParseErrors()); |
|
238 |
+ } |
| 195 |
239 |
|
| 196 |
|
- $this->assertEquals(1, $package->getFunctions()->count()); |
| 197 |
|
- $this->assertEquals(1, $package->getClasses()->count()); |
|
240 |
+ /** |
|
241 |
+ * testRunnerHasParseErrorsReturnsTrueForInvalidSource |
|
242 |
+ * |
|
243 |
+ * @return void |
|
244 |
+ * @covers PHP_Depend_TextUI_Runner |
|
245 |
+ * @group pdepend |
|
246 |
+ * @group pdepend::textui |
|
247 |
+ * @group unittest |
|
248 |
+ */ |
|
249 |
+ public function testRunnerHasParseErrorsReturnsTrueForInvalidSource() |
|
250 |
+ { |
|
251 |
+ $runner = new PHP_Depend_TextUI_Runner(); |
|
252 |
+ $runner->addLogger('dummy-logger', self::createRunResourceURI('pdepend.dummy')); |
|
253 |
+ $runner->setSourceArguments(array(self::createCodeResourceURI('textui/Runner/' . __FUNCTION__ . '.php'))); |
| 198 |
254 |
|
| 199 |
|
- $function = $package->getFunctions()->current(); |
| 200 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 201 |
|
- $this->assertEquals('foo', $function->getName()); |
| 202 |
|
- $this->assertEquals(0, $function->getExceptionClasses()->count()); |
|
255 |
+ try { |
|
256 |
+ $runner->run(); |
|
257 |
+ } catch (Exception $e) {} |
| 203 |
258 |
|
| 204 |
|
- $code->next(); |
|
259 |
+ $this->assertTrue($runner->hasParseErrors()); |
|
260 |
+ } |
| 205 |
261 |
|
| 206 |
|
- $package = $code->current(); |
| 207 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 208 |
|
- $this->assertEquals('pdepend.test2', $package->getName()); |
|
262 |
+ /** |
|
263 |
+ * testRunnerGetParseErrorsReturnsArrayWithParsingExceptionMessages |
|
264 |
+ * |
|
265 |
+ * @return void |
|
266 |
+ * @covers PHP_Depend_TextUI_Runner |
|
267 |
+ * @group pdepend |
|
268 |
+ * @group pdepend::textui |
|
269 |
+ * @group unittest |
|
270 |
+ */ |
|
271 |
+ public function testRunnerGetParseErrorsReturnsArrayWithParsingExceptionMessages() |
|
272 |
+ { |
|
273 |
+ $runner = new PHP_Depend_TextUI_Runner(); |
|
274 |
+ $runner->addLogger('dummy-logger', self::createRunResourceURI('pdepend.dummy')); |
|
275 |
+ $runner->setSourceArguments(array(self::createCodeResourceURI('textui/Runner/' . __FUNCTION__ . '.php'))); |
| 209 |
276 |
|
| 210 |
|
- unlink($fileName); |
|
277 |
+ try { |
|
278 |
+ $runner->run(); |
|
279 |
+ } catch (Exception $e) {} |
|
280 |
+ |
|
281 |
+ $errors = $runner->getParseErrors(); |
|
282 |
+ $this->assertContains('Unexpected token: }, line: 10, col: 1, file: ', $errors[0]); |
|
283 |
+ |
|
284 |
+ $this->assertTrue($runner->hasParseErrors()); |
| 211 |
285 |
} |
| 212 |
286 |
|
| 213 |
|
- public function testSupportBadDocumentation() |
|
287 |
+ /** |
|
288 |
+ * testRunnerThrowsExceptionForUndefinedLoggerClass |
|
289 |
+ * |
|
290 |
+ * @return void |
|
291 |
+ * @covers PHP_Depend_TextUI_Runner |
|
292 |
+ * @group pdepend |
|
293 |
+ * @group pdepend::textui |
|
294 |
+ * @group unittest |
|
295 |
+ * @expectedException RuntimeException |
|
296 |
+ */ |
|
297 |
+ public function testRunnerThrowsExceptionForUndefinedLoggerClass() |
| 214 |
298 |
{ |
| 215 |
|
- $fileName = self::createRunResourceURI('pdepend.dummy'); |
| 216 |
|
- if (file_exists($fileName)) { |
| 217 |
|
- unlink($fileName); |
| 218 |
|
- } |
| 219 |
|
- |
| 220 |
299 |
$runner = new PHP_Depend_TextUI_Runner(); |
| 221 |
|
- $runner->setSourceArguments(array(dirname(__FILE__). '/../_code/code-without-comments')); |
| 222 |
|
- $runner->setSupportBadDocumentation(); |
| 223 |
|
- $runner->addLogger('dummy-logger', $fileName); |
|
300 |
+ $runner->addLogger('FooBarLogger', self::createRunResourceURI('log.xml')); |
|
301 |
+ $runner->run(); |
|
302 |
+ } |
| 224 |
303 |
|
|
304 |
+ /** |
|
305 |
+ * Executes the runner class and returns an array with package statistics. |
|
306 |
+ * |
|
307 |
+ * @param array PHP_Depend_TextUI_Runner $runner The runner instance. |
|
308 |
+ * @param string $pathName The source path. |
|
309 |
+ * |
|
310 |
+ * @return array |
|
311 |
+ */ |
|
312 |
+ private function _runRunnerAndReturnStatistics(PHP_Depend_TextUI_Runner $runner, $pathName) |
|
313 |
+ { |
|
314 |
+ $logFile = self::createRunResourceURI('pdepend.dummy'); |
|
315 |
+ |
|
316 |
+ $runner->setSourceArguments(array($pathName)); |
|
317 |
+ $runner->addLogger('dummy-logger', $logFile); |
|
318 |
+ |
| 225 |
319 |
ob_start(); |
| 226 |
320 |
$runner->run(); |
| 227 |
321 |
ob_end_clean(); |
| 228 |
322 |
|
| 229 |
|
- $this->assertFileExists($fileName); |
| 230 |
|
- |
| 231 |
|
- $data = unserialize(file_get_contents($fileName)); |
| 232 |
|
- |
|
323 |
+ $data = unserialize(file_get_contents($logFile)); |
| 233 |
324 |
$code = $data['code']; |
| 234 |
|
- $this->assertType('PHP_Depend_Code_NodeIterator', $code); |
| 235 |
|
- $this->assertEquals(1, $code->count()); |
| 236 |
325 |
|
| 237 |
|
- $code->rewind(); |
|
326 |
+ $actual = array(); |
|
327 |
+ foreach ($code as $package) { |
|
328 |
+ $exceptions = 0; |
|
329 |
+ foreach ($package->getFunctions() as $function) { |
|
330 |
+ $exceptions += $function->getExceptionClasses()->count(); |
|
331 |
+ } |
| 238 |
332 |
|
| 239 |
|
- $package = $code->current(); |
| 240 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 241 |
|
- $this->assertEquals(PHP_Depend_BuilderI::DEFAULT_PACKAGE, $package->getName()); |
|
333 |
+ $actual[$package->getName()] = array( |
|
334 |
+ 'functions' => $package->getFunctions()->count(), |
|
335 |
+ 'classes' => $package->getClasses()->count(), |
|
336 |
+ 'interfaces' => $package->getInterfaces()->count(), |
|
337 |
+ 'exceptions' => $exceptions |
|
338 |
+ ); |
|
339 |
+ } |
|
340 |
+ ksort($actual); |
| 242 |
341 |
|
| 243 |
|
- $this->assertEquals(7, $package->getClasses()->count()); |
| 244 |
|
- $this->assertEquals(3, $package->getInterfaces()->count()); |
| 245 |
|
- |
| 246 |
|
- unlink($fileName); |
|
342 |
+ return $actual; |
| 247 |
343 |
} |
| 248 |
|
-} |
|
344 |
+} |
| 200 |
222 |
* correct. |
| 201 |
223 |
* |
| 202 |
224 |
* @return void |
|
225 |
+ * @covers PHP_Depend_TextUI_Command |
|
226 |
+ * @group pdepend |
|
227 |
+ * @group pdepend::textui |
|
228 |
+ * @group unittest |
| 203 |
229 |
*/ |
| 204 |
230 |
public function testCommandHandlesWithoutAnnotationsOptionCorrect() |
| 205 |
231 |
{ |
| 206 |
|
- $logFile = self::createRunResourceURI('pdepend.dummy'); |
| 207 |
|
- $source = realpath(dirname(__FILE__) . '/../_code'); |
|
232 |
+ $expected = array( |
|
233 |
+ 'pdepend.test' => array( |
|
234 |
+ 'functions' => 1, |
|
235 |
+ 'classes' => 1, |
|
236 |
+ 'interfaces' => 0, |
|
237 |
+ 'exceptions' => 0 |
|
238 |
+ ), |
|
239 |
+ 'pdepend.test2' => array( |
|
240 |
+ 'functions' => 0, |
|
241 |
+ 'classes' => 1, |
|
242 |
+ 'interfaces' => 0, |
|
243 |
+ 'exceptions' => 0 |
|
244 |
+ ) |
|
245 |
+ ); |
| 208 |
246 |
|
| 209 |
|
- $argv = array( |
| 210 |
|
- '--suffix=inc', |
| 211 |
|
- '--without-annotations', |
| 212 |
|
- '--coderank-mode=property', |
| 213 |
|
- '--dummy-logger=' . $logFile, |
| 214 |
|
- $source |
|
247 |
+ $actual = $this->_runCommandAndReturnStatistics( |
|
248 |
+ array( |
|
249 |
+ '--suffix=inc', |
|
250 |
+ '--without-annotations', |
|
251 |
+ '--coderank-mode=property' |
|
252 |
+ ), |
|
253 |
+ self::createCodeResourceURI('textui/Command/' . __FUNCTION__) |
| 215 |
254 |
); |
| 216 |
255 |
|
| 217 |
|
- if (file_exists($logFile)) { |
| 218 |
|
- unlink($logFile); |
| 219 |
|
- } |
|
256 |
+ $this->assertEquals($expected, $actual); |
|
257 |
+ } |
| 220 |
258 |
|
| 221 |
|
- list($exitCode, $actual) = $this->_executeCommand($argv); |
|
259 |
+ /** |
|
260 |
+ * testCommandHandlesBadDocumentedSourceCode |
|
261 |
+ * |
|
262 |
+ * @return void |
|
263 |
+ * @covers PHP_Depend_TextUI_Command |
|
264 |
+ * @group pdepend |
|
265 |
+ * @group pdepend::textui |
|
266 |
+ * @group unittest |
|
267 |
+ */ |
|
268 |
+ public function testCommandHandlesBadDocumentedSourceCode() |
|
269 |
+ { |
|
270 |
+ $expected = array( |
|
271 |
+ '+global' => array( |
|
272 |
+ 'functions' => 1, |
|
273 |
+ 'classes' => 7, |
|
274 |
+ 'interfaces' => 3, |
|
275 |
+ 'exceptions' => 0 |
|
276 |
+ ) |
|
277 |
+ ); |
| 222 |
278 |
|
| 223 |
|
- $this->assertFileExists($logFile); |
|
279 |
+ $actual = $this->_runCommandAndReturnStatistics( |
|
280 |
+ array(), |
|
281 |
+ self::createCodeResourceURI('code-without-comments') |
|
282 |
+ ); |
| 224 |
283 |
|
| 225 |
|
- $data = unserialize(file_get_contents($logFile)); |
| 226 |
|
- |
| 227 |
|
- $code = $data['code']; |
| 228 |
|
- $this->assertType('PHP_Depend_Code_NodeIterator', $code); |
| 229 |
|
- $this->assertEquals(2, $code->count()); |
| 230 |
|
- |
| 231 |
|
- $code->rewind(); |
| 232 |
|
- |
| 233 |
|
- $package = $code->current(); |
| 234 |
|
- |
| 235 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 236 |
|
- $this->assertEquals('pdepend.test', $package->getName()); |
| 237 |
|
- |
| 238 |
|
- $this->assertEquals(1, $package->getFunctions()->count()); |
| 239 |
|
- $this->assertEquals(1, $package->getClasses()->count()); |
| 240 |
|
- |
| 241 |
|
- $function = $package->getFunctions()->current(); |
| 242 |
|
- $this->assertType('PHP_Depend_Code_Function', $function); |
| 243 |
|
- $this->assertEquals('foo', $function->getName()); |
| 244 |
|
- $this->assertEquals(0, $function->getExceptionClasses()->count()); |
| 245 |
|
- |
| 246 |
|
- $code->next(); |
| 247 |
|
- |
| 248 |
|
- $package = $code->current(); |
| 249 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 250 |
|
- $this->assertEquals('pdepend.test2', $package->getName()); |
| 251 |
|
- |
| 252 |
|
- unlink($logFile); |
|
284 |
+ $this->assertEquals($expected, $actual); |
| 253 |
285 |
} |
| 254 |
286 |
|
| 255 |
287 |
/** |
| 256 |
|
- * Tests that the command handles the <b>--bad-documentation</b> option |
| 257 |
|
- * correct. |
|
288 |
+ * Executes the command class and returns an array with package statistics. |
| 258 |
289 |
* |
| 259 |
|
- * @return void |
|
290 |
+ * @param array $argv The cli arguments. |
|
291 |
+ * @param string $pathName The source path. |
|
292 |
+ * |
|
293 |
+ * @return array |
| 260 |
294 |
*/ |
| 261 |
|
- public function testCommandHandlesBadDocumentationOptionCorrect() |
|
295 |
+ private function _runCommandAndReturnStatistics(array $argv, $pathName) |
| 262 |
296 |
{ |
| 263 |
297 |
$logFile = self::createRunResourceURI('pdepend.dummy'); |
| 264 |
|
- $source = realpath(dirname(__FILE__) . '/../_code/code-without-comments'); |
| 265 |
298 |
|
| 266 |
|
- $argv = array( |
| 267 |
|
- '--bad-documentation', |
| 268 |
|
- '--dummy-logger=' . $logFile, |
| 269 |
|
- $source |
| 270 |
|
- ); |
|
299 |
+ $argv[] = '--dummy-logger=' . $logFile; |
|
300 |
+ $argv[] = $pathName; |
| 271 |
301 |
|
| 272 |
302 |
if (file_exists($logFile)) { |
| 273 |
303 |
unlink($logFile); |
| 274 |
304 |
} |
| 275 |
305 |
|
| 276 |
|
- list($exitCode, $actual) = $this->_executeCommand($argv); |
| 277 |
|
- |
| 278 |
|
- $this->assertFileExists($logFile); |
| 279 |
|
- |
|
306 |
+ $this->_executeCommand($argv); |
|
307 |
+ |
| 280 |
308 |
$data = unserialize(file_get_contents($logFile)); |
| 281 |
|
- |
| 282 |
309 |
$code = $data['code']; |
| 283 |
|
- $this->assertType('PHP_Depend_Code_NodeIterator', $code); |
| 284 |
|
- $this->assertEquals(1, $code->count()); |
| 285 |
310 |
|
| 286 |
|
- $code->rewind(); |
|
311 |
+ $actual = array(); |
|
312 |
+ foreach ($code as $package) { |
|
313 |
+ $exceptions = 0; |
|
314 |
+ foreach ($package->getFunctions() as $function) { |
|
315 |
+ $exceptions += $function->getExceptionClasses()->count(); |
|
316 |
+ } |
| 287 |
317 |
|
| 288 |
|
- $package = $code->current(); |
| 289 |
|
- $this->assertType('PHP_Depend_Code_Package', $package); |
| 290 |
|
- $this->assertEquals(PHP_Depend_BuilderI::DEFAULT_PACKAGE, $package->getName()); |
|
318 |
+ $actual[$package->getName()] = array( |
|
319 |
+ 'functions' => $package->getFunctions()->count(), |
|
320 |
+ 'classes' => $package->getClasses()->count(), |
|
321 |
+ 'interfaces' => $package->getInterfaces()->count(), |
|
322 |
+ 'exceptions' => $exceptions |
|
323 |
+ ); |
|
324 |
+ } |
|
325 |
+ ksort($actual); |
| 291 |
326 |
|
| 292 |
|
- $this->assertEquals(7, $package->getClasses()->count()); |
| 293 |
|
- $this->assertEquals(3, $package->getInterfaces()->count()); |
| 294 |
|
- |
| 295 |
|
- unlink($logFile); |
|
327 |
+ return $actual; |
| 296 |
328 |
} |
| 297 |
329 |
|
| 298 |
330 |
/** |
| 299 |
331 |
* Tests that the command interpretes a "-d key" as "on". |
| 300 |
332 |
* |
| 301 |
333 |
* @return void |
|
334 |
+ * @covers PHP_Depend_TextUI_Command |
|
335 |
+ * @group pdepend |
|
336 |
+ * @group pdepend::textui |
|
337 |
+ * @group unittest |
| 302 |
338 |
*/ |
| 303 |
339 |
public function testCommandHandlesIniOptionWithoutValueToON() |
| 304 |
340 |
{ |
| 379 |
423 |
|
| 380 |
424 |
list($exitCode, $actual) = $this->_executeCommand($argv); |
| 381 |
425 |
|
| 382 |
|
- // Remove temp config file |
| 383 |
|
- unlink($configFile); |
| 384 |
|
- |
| 385 |
|
- $this->assertEquals(PHP_Depend_TextUI_Runner::SUCCESS_EXIT, $exitCode); |
| 386 |
|
- $this->assertNotNull(PHP_Depend_Util_ConfigurationInstance::get()); |
| 387 |
|
- |
| 388 |
426 |
$test = isset(PHP_Depend_Util_ConfigurationInstance::get()->test); |
| 389 |
427 |
$this->assertTrue($test); |
| 390 |
428 |
} |
| 391 |
429 |
|
| 392 |
430 |
/** |
|
431 |
+ * testTextUiCommandOutputContainsExpectedCoverageReportOption |
|
432 |
+ * |
|
433 |
+ * @return void |
|
434 |
+ * @covers PHP_Depend_TextUI_Command |
|
435 |
+ * @group pdepend |
|
436 |
+ * @group pdepend::textui |
|
437 |
+ * @group unittest |
|
438 |
+ */ |
|
439 |
+ public function testTextUiCommandOutputContainsExpectedCoverageReportOption() |
|
440 |
+ { |
|
441 |
+ list($exitCode, $actual) = $this->_executeCommand(array()); |
|
442 |
+ $this->assertContains('--coverage-report=<file>', $actual); |
|
443 |
+ } |
|
444 |
+ |
|
445 |
+ /** |
|
446 |
+ * testTextUiCommandFailesWithExpectedErrorCodeWhenCoverageReportFileDoesNotExist |
|
447 |
+ * |
|
448 |
+ * @return void |
|
449 |
+ * @covers PHP_Depend_TextUI_Command |
|
450 |
+ * @group pdepend |
|
451 |
+ * @group pdepend::textui |
|
452 |
+ * @group unittest |
|
453 |
+ */ |
|
454 |
+ public function testTextUiCommandFailesWithExpectedErrorCodeWhenCoverageReportFileDoesNotExist() |
|
455 |
+ { |
|
456 |
+ $argv = array( |
|
457 |
+ '--coverage-report=' . self::createRunResourceURI('foobar'), |
|
458 |
+ '--dummy-logger=' . self::createRunResourceURI('pdepend.dummy'), |
|
459 |
+ __FILE__, |
|
460 |
+ ); |
|
461 |
+ |
|
462 |
+ list($exitCode, $actual) = $this->_executeCommand($argv); |
|
463 |
+ |
|
464 |
+ $this->assertEquals(PHP_Depend_TextUI_Command::INPUT_ERROR, $exitCode); |
|
465 |
+ } |
|
466 |
+ |
|
467 |
+ /** |
|
468 |
+ * testTextUiCommandAcceptsExistingFileForCoverageReportOption |
|
469 |
+ * |
|
470 |
+ * @return void |
|
471 |
+ * @covers PHP_Depend_TextUI_Command |
|
472 |
+ * @group pdepend |
|
473 |
+ * @group pdepend::textui |
|
474 |
+ * @group unittest |
|
475 |
+ */ |
|
476 |
+ public function testTextUiCommandAcceptsExistingFileForCoverageReportOption() |
|
477 |
+ { |
|
478 |
+ $argv = array( |
|
479 |
+ '--coverage-report=' . dirname(__FILE__) . '/_files/clover.xml', |
|
480 |
+ '--dummy-logger=' . self::createRunResourceURI('pdepend.dummy'), |
|
481 |
+ __FILE__, |
|
482 |
+ ); |
|
483 |
+ |
|
484 |
+ list($exitCode, $actual) = $this->_executeCommand($argv); |
|
485 |
+ |
|
486 |
+ $this->assertEquals(PHP_Depend_TextUI_Runner::SUCCESS_EXIT, $exitCode); |
|
487 |
+ } |
|
488 |
+ |
|
489 |
+ /** |
| 393 |
490 |
* Tests that the command fails for an invalid config file. |
| 394 |
491 |
* |
| 395 |
492 |
* @return void |
|
493 |
+ * @covers PHP_Depend_TextUI_Command |
|
494 |
+ * @group pdepend |
|
495 |
+ * @group pdepend::textui |
|
496 |
+ * @group unittest |
| 396 |
497 |
*/ |
| 397 |
498 |
public function testCommandFailsIfAnInvalidConfigFileWasSpecified() |
| 398 |
499 |
{ |
| 399 |
500 |
$configFile = self::createRunResourceURI('config.xml'); |
| 400 |
|
- if (file_exists($configFile) === true) { |
| 401 |
|
- unlink($configFile); |
| 402 |
|
- } |
| 403 |
501 |
|
| 404 |
|
- $argv = array( |
| 405 |
|
- '--configuration=' . $configFile, |
| 406 |
|
- dirname(__FILE__) |
| 407 |
|
- ); |
|
502 |
+ $argv = array('--configuration=' . $configFile, __FILE__); |
| 408 |
503 |
|
| 409 |
504 |
list($exitCode, $actual) = $this->_executeCommand($argv); |
| 410 |
505 |
|
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category QualityAssurance |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
43 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
44 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
45 |
+ * @version SVN: $Id$ |
|
46 |
+ * @link http://pdepend.org/ |
|
47 |
+ */ |
|
48 |
+ |
|
49 |
+require_once dirname(__FILE__) . '/AbstractTest.php'; |
|
50 |
+ |
|
51 |
+/** |
|
52 |
+ * Test case that parses several files where we have found errors in PHP_Depend's |
|
53 |
+ * parser implementation. |
|
54 |
+ * |
|
55 |
+ * @category QualityAssurance |
|
56 |
+ * @package PHP_Depend |
|
57 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
58 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
59 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
60 |
+ * @version Release: @package_version@ |
|
61 |
+ * @link http://pdepend.org/ |
|
62 |
+ */ |
|
63 |
+class PHP_Depend_ParserRegressionTest extends PHP_Depend_AbstractTest |
|
64 |
+{ |
|
65 |
+ /** |
|
66 |
+ * Tests that the parser handles the given source file. |
|
67 |
+ * |
|
68 |
+ * @param string $pathName Name of the file to parse. |
|
69 |
+ * |
|
70 |
+ * @return void |
|
71 |
+ * @covers stdClass |
|
72 |
+ * @group pdepend |
|
73 |
+ * @group pdepend::parser |
|
74 |
+ * @group regressiontest |
|
75 |
+ * @dataProvider dataProviderSourceFiles |
|
76 |
+ */ |
|
77 |
+ public function testParserHandlesSourceFileWithoutException($pathName) |
|
78 |
+ { |
|
79 |
+ self::parseSource($pathName); |
|
80 |
+ } |
|
81 |
+ |
|
82 |
+ /** |
|
83 |
+ * Returns an array with test source files. |
|
84 |
+ * |
|
85 |
+ * @return array(array) |
|
86 |
+ */ |
|
87 |
+ public static function dataProviderSourceFiles() |
|
88 |
+ { |
|
89 |
+ $files = array(); |
|
90 |
+ foreach (new DirectoryIterator(self::createCodeResourceURI('parser_regression')) as $file) { |
|
91 |
+ if ($file->isFile()) { |
|
92 |
+ $files[] = array(realpath($file->getPathname())); |
|
93 |
+ } |
|
94 |
+ } |
|
95 |
+ return $files; |
|
96 |
+ } |
|
97 |
+} |
| 65 |
65 |
class PHP_Depend_Builder_DefaultTest extends PHP_Depend_AbstractTest |
| 66 |
66 |
{ |
| 67 |
67 |
/** |
|
68 |
+ * testBuilderAddsMultiplePackagesForClassesToListOfPackages |
|
69 |
+ * |
|
70 |
+ * @return void |
|
71 |
+ * @covers PHP_Depend_Builder_Default |
|
72 |
+ * @group pdepend |
|
73 |
+ * @group pdepend::builder |
|
74 |
+ * @group unittest |
|
75 |
+ */ |
|
76 |
+ public function testBuilderAddsMultiplePackagesForClassesToListOfPackages() |
|
77 |
+ { |
|
78 |
+ $builder = new PHP_Depend_Builder_Default(); |
|
79 |
+ |
|
80 |
+ $package = $builder->buildPackage(__FUNCTION__); |
|
81 |
+ $package->addType($builder->buildClass(__FUNCTION__)); |
|
82 |
+ |
|
83 |
+ $package = $builder->buildPackage(__CLASS__); |
|
84 |
+ $package->addType($builder->buildClass(__CLASS__)); |
|
85 |
+ |
|
86 |
+ $this->assertEquals(2, $builder->getPackages()->count()); |
|
87 |
+ } |
|
88 |
+ |
|
89 |
+ /** |
|
90 |
+ * testBuilderAddsMultiplePackagesForFunctionsToListOfPackages |
|
91 |
+ * |
|
92 |
+ * @return void |
|
93 |
+ * @covers PHP_Depend_Builder_Default |
|
94 |
+ * @group pdepend |
|
95 |
+ * @group pdepend::builder |
|
96 |
+ * @group unittest |
|
97 |
+ */ |
|
98 |
+ public function testBuilderAddsMultiplePackagesForFunctionsToListOfPackages() |
|
99 |
+ { |
|
100 |
+ $builder = new PHP_Depend_Builder_Default(); |
|
101 |
+ |
|
102 |
+ $package = $builder->buildPackage(__FUNCTION__); |
|
103 |
+ $builder->buildFunction(__FUNCTION__); |
|
104 |
+ |
|
105 |
+ $package = $builder->buildPackage(__CLASS__); |
|
106 |
+ $builder->buildFunction(__CLASS__); |
|
107 |
+ |
|
108 |
+ $this->assertEquals(2, $builder->getPackages()->count()); |
|
109 |
+ } |
|
110 |
+ |
|
111 |
+ /** |
|
112 |
+ * testBuilderNotAddsNewPackagesOnceItHasReturnedTheListOfPackages |
|
113 |
+ * |
|
114 |
+ * @return void |
|
115 |
+ * @covers PHP_Depend_Builder_Default |
|
116 |
+ * @group pdepend |
|
117 |
+ * @group pdepend::builder |
|
118 |
+ * @group unittest |
|
119 |
+ */ |
|
120 |
+ public function testBuilderNotAddsNewPackagesOnceItHasReturnedTheListOfPackages() |
|
121 |
+ { |
|
122 |
+ $builder = new PHP_Depend_Builder_Default(); |
|
123 |
+ |
|
124 |
+ $package = $builder->buildPackage(__FUNCTION__); |
|
125 |
+ $package->addFunction($builder->buildFunction(__FUNCTION__)); |
|
126 |
+ |
|
127 |
+ $builder->getPackages(); |
|
128 |
+ |
|
129 |
+ $package = $builder->buildPackage(__CLASS__); |
|
130 |
+ $package->addType($builder->buildClass(__CLASS__)); |
|
131 |
+ |
|
132 |
+ $this->assertEquals(1, $builder->getPackages()->count()); |
|
133 |
+ } |
|
134 |
+ |
|
135 |
+ /** |
| 68 |
136 |
* Tests that the node builder creates a class for the same name only once. |
| 69 |
137 |
* |
| 70 |
138 |
* @return void |
|
139 |
+ * @covers PHP_Depend_Builder_Default |
|
140 |
+ * @group pdepend |
|
141 |
+ * @group pdepend::builder |
|
142 |
+ * @group unittest |
| 71 |
143 |
*/ |
| 72 |
144 |
public function testBuildClassUnique() |
| 73 |
145 |
{ |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category QualityAssurance |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Parser |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once 'PHPUnit/Framework.php'; |
|
51 |
+ |
|
52 |
+require_once dirname(__FILE__) . '/FunctionNameParserImplTest.php'; |
|
53 |
+ |
|
54 |
+/** |
|
55 |
+ * Main test suite for the PHP_Depend_Parser package. |
|
56 |
+ * |
|
57 |
+ * @category QualityAssurance |
|
58 |
+ * @package PHP_Depend |
|
59 |
+ * @subpackage Parser |
|
60 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
61 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
62 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
63 |
+ * @version Release: @package_version@ |
|
64 |
+ * @link http://pdepend.org/ |
|
65 |
+ */ |
|
66 |
+class PHP_Depend_Parser_AllTests extends PHPUnit_Framework_TestSuite |
|
67 |
+{ |
|
68 |
+ /** |
|
69 |
+ * Constructs a new test suite instance. |
|
70 |
+ */ |
|
71 |
+ public function __construct() |
|
72 |
+ { |
|
73 |
+ $this->setName('PHP::Depend::Parser::AllTests'); |
|
74 |
+ |
|
75 |
+ $this->addTestSuite('PHP_Depend_Parser_FunctionNameParserImplTest'); |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ /** |
|
79 |
+ * Returns a configured test suite instance. |
|
80 |
+ * |
|
81 |
+ * @return PHP_Depend_Parser_AllTests |
|
82 |
+ */ |
|
83 |
+ public static function suite() |
|
84 |
+ { |
|
85 |
+ return new PHP_Depend_Parser_AllTests(); |
|
86 |
+ } |
|
87 |
+} |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category QualityAssurance |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Parser |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once dirname(__FILE__) . '/../AbstractTest.php'; |
|
51 |
+ |
|
52 |
+require_once 'PHP/Depend/Token.php'; |
|
53 |
+require_once 'PHP/Depend/TokenizerI.php'; |
|
54 |
+require_once 'PHP/Depend/Parser/TokenStack.php'; |
|
55 |
+require_once 'PHP/Depend/Parser/FunctionNameParserImpl.php'; |
|
56 |
+ |
|
57 |
+/** |
|
58 |
+ * Test case for the {@link PHP_Depend_Parser_FunctionNameParserImpl} class. |
|
59 |
+ * |
|
60 |
+ * @category QualityAssurance |
|
61 |
+ * @package PHP_Depend |
|
62 |
+ * @subpackage Parser |
|
63 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
64 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
65 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
66 |
+ * @version Release: @package_version@ |
|
67 |
+ * @link http://pdepend.org/ |
|
68 |
+ */ |
|
69 |
+class PHP_Depend_Parser_FunctionNameParserImplTest extends PHP_Depend_AbstractTest |
|
70 |
+{ |
|
71 |
+ /** |
|
72 |
+ * testParserHandlesTNamespaceAsValidFunctionName |
|
73 |
+ * |
|
74 |
+ * @return void |
|
75 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
76 |
+ * @group pdepend |
|
77 |
+ * @group pdepend::parser |
|
78 |
+ * @group unittest |
|
79 |
+ */ |
|
80 |
+ public function testParserHandlesTNamespaceAsValidFunctionName() |
|
81 |
+ { |
|
82 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
83 |
+ |
|
84 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
85 |
+ $tokenizer->expects($this->once()) |
|
86 |
+ ->method('peek') |
|
87 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_NAMESPACE)); |
|
88 |
+ $tokenizer->expects($this->once()) |
|
89 |
+ ->method('next') |
|
90 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
91 |
+ |
|
92 |
+ $stack = $this->getMock('PHP_Depend_Parser_TokenStack'); |
|
93 |
+ |
|
94 |
+ $parser->setTokenizer($tokenizer); |
|
95 |
+ $parser->setTokenStack($stack); |
|
96 |
+ |
|
97 |
+ $parser->parse(); |
|
98 |
+ } |
|
99 |
+ |
|
100 |
+ /** |
|
101 |
+ * testParserHandlesTStringAsValidFunctionName |
|
102 |
+ * |
|
103 |
+ * @return void |
|
104 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
105 |
+ * @group pdepend |
|
106 |
+ * @group pdepend::parser |
|
107 |
+ * @group unittest |
|
108 |
+ */ |
|
109 |
+ public function testParserHandlesTStringAsValidFunctionName() |
|
110 |
+ { |
|
111 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
112 |
+ |
|
113 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
114 |
+ $tokenizer->expects($this->once()) |
|
115 |
+ ->method('peek') |
|
116 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_STRING)); |
|
117 |
+ $tokenizer->expects($this->once()) |
|
118 |
+ ->method('next') |
|
119 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
120 |
+ |
|
121 |
+ $stack = $this->getMock('PHP_Depend_Parser_TokenStack'); |
|
122 |
+ |
|
123 |
+ $parser->setTokenizer($tokenizer); |
|
124 |
+ $parser->setTokenStack($stack); |
|
125 |
+ |
|
126 |
+ $parser->parse(); |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ /** |
|
130 |
+ * testParserAddsValidTokenToTokenStackInstance |
|
131 |
+ * |
|
132 |
+ * @return void |
|
133 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
134 |
+ * @group pdepend |
|
135 |
+ * @group pdepend::parser |
|
136 |
+ * @group unittest |
|
137 |
+ */ |
|
138 |
+ public function testParserAddsValidTokenToTokenStackInstance() |
|
139 |
+ { |
|
140 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
141 |
+ |
|
142 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
143 |
+ $tokenizer->expects($this->once()) |
|
144 |
+ ->method('peek') |
|
145 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_STRING)); |
|
146 |
+ $tokenizer->expects($this->once()) |
|
147 |
+ ->method('next') |
|
148 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
149 |
+ |
|
150 |
+ $stack = $this->getMock('PHP_Depend_Parser_TokenStack'); |
|
151 |
+ $stack->expects($this->once()) |
|
152 |
+ ->method('add'); |
|
153 |
+ |
|
154 |
+ $parser->setTokenizer($tokenizer); |
|
155 |
+ $parser->setTokenStack($stack); |
|
156 |
+ |
|
157 |
+ $parser->parse(); |
|
158 |
+ } |
|
159 |
+ |
|
160 |
+ /** |
|
161 |
+ * testParserThrowsExceptionForUnexpectedTokenTArray |
|
162 |
+ * |
|
163 |
+ * @return void |
|
164 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
165 |
+ * @group pdepend |
|
166 |
+ * @group pdepend::parser |
|
167 |
+ * @group unittest |
|
168 |
+ * @expectedException PHP_Depend_Parser_UnexpectedTokenException |
|
169 |
+ */ |
|
170 |
+ public function testParserThrowsExceptionForUnexpectedTokenTArray() |
|
171 |
+ { |
|
172 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
173 |
+ |
|
174 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
175 |
+ $tokenizer->expects($this->once()) |
|
176 |
+ ->method('peek') |
|
177 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_ARRAY)); |
|
178 |
+ $tokenizer->expects($this->once()) |
|
179 |
+ ->method('next') |
|
180 |
+ ->will($this->returnValue($this->getMock('PHP_Depend_Token', array(), array(), '', false))); |
|
181 |
+ |
|
182 |
+ $parser->setTokenizer($tokenizer); |
|
183 |
+ |
|
184 |
+ $parser->parse(); |
|
185 |
+ } |
|
186 |
+ |
|
187 |
+ /** |
|
188 |
+ * testParserThrowsExceptionForUnexpectedTokenStreamEnd |
|
189 |
+ * |
|
190 |
+ * @return void |
|
191 |
+ * @covers PHP_Depend_Parser_FunctionNameParserImpl |
|
192 |
+ * @group pdepend |
|
193 |
+ * @group pdepend::parser |
|
194 |
+ * @group unittest |
|
195 |
+ * @expectedException PHP_Depend_Parser_TokenStreamEndException |
|
196 |
+ */ |
|
197 |
+ public function testParserThrowsExceptionForUnexpectedTokenStreamEnd() |
|
198 |
+ { |
|
199 |
+ $parser = new PHP_Depend_Parser_FunctionNameParserImpl(); |
|
200 |
+ |
|
201 |
+ $tokenizer = $this->getMock('PHP_Depend_TokenizerI'); |
|
202 |
+ $tokenizer->expects($this->once()) |
|
203 |
+ ->method('peek') |
|
204 |
+ ->will($this->returnValue(PHP_Depend_TokenizerI::T_EOF)); |
|
205 |
+ |
|
206 |
+ $parser->setTokenizer($tokenizer); |
|
207 |
+ |
|
208 |
+ $parser->parse(); |
|
209 |
+ } |
|
210 |
+} |
| 65 |
67 |
*/ |
| 66 |
68 |
class PHP_Depend_Visitor_DefaultListenerTest extends PHP_Depend_AbstractTest |
| 67 |
69 |
{ |
|
70 |
+ /** |
|
71 |
+ * testDefaultImplementationCallsListeners |
|
72 |
+ * |
|
73 |
+ * @return void |
|
74 |
+ * @covers PHP_Depend_Visitor_AbstractListener |
|
75 |
+ * @group pdepend |
|
76 |
+ * @group pdepend::visitor |
|
77 |
+ * @group unittest |
|
78 |
+ */ |
| 68 |
79 |
public function testDefaultImplementationCallsListeners() |
| 69 |
80 |
{ |
| 70 |
81 |
$codeUri = self::createCodeResourceURI('visitor/' . __FUNCTION__ . '.php'); |
| 71 |
82 |
$packages = self::parseSource($codeUri); |
| 72 |
|
- $package = $packages->current(); |
| 73 |
|
- |
|
83 |
+ |
| 74 |
84 |
$listener = new PHP_Depend_Visitor_TestListener(); |
| 75 |
85 |
$visitor = new PHP_Depend_Visitor_DefaultVisitorDummy(); |
| 76 |
86 |
$visitor->addVisitListener($listener); |
| 77 |
|
- $visitor->visitPackage($package); |
| 78 |
|
- |
| 79 |
|
- $this->assertArrayHasKey($codeUri . '#start', $listener->nodes); |
| 80 |
|
- $this->assertArrayHasKey($codeUri . '#end', $listener->nodes); |
| 81 |
|
- $this->assertArrayHasKey('package#start', $listener->nodes); |
| 82 |
|
- $this->assertArrayHasKey('package#end', $listener->nodes); |
| 83 |
|
- $this->assertArrayHasKey('clazz#start', $listener->nodes); |
| 84 |
|
- $this->assertArrayHasKey('clazz#end', $listener->nodes); |
| 85 |
|
- $this->assertArrayHasKey('func#start', $listener->nodes); |
| 86 |
|
- $this->assertArrayHasKey('func#end', $listener->nodes); |
| 87 |
|
- $this->assertArrayHasKey('interfs#start', $listener->nodes); |
| 88 |
|
- $this->assertArrayHasKey('interfs#end', $listener->nodes); |
| 89 |
|
- $this->assertArrayHasKey('m1#start', $listener->nodes); |
| 90 |
|
- $this->assertArrayHasKey('m1#end', $listener->nodes); |
| 91 |
|
- $this->assertArrayHasKey('m2#start', $listener->nodes); |
| 92 |
|
- $this->assertArrayHasKey('m2#end', $listener->nodes); |
| 93 |
|
- $this->assertArrayHasKey('m3#start', $listener->nodes); |
| 94 |
|
- $this->assertArrayHasKey('m3#end', $listener->nodes); |
| 95 |
|
- $this->assertArrayHasKey('m4#start', $listener->nodes); |
| 96 |
|
- $this->assertArrayHasKey('m4#end', $listener->nodes); |
| 97 |
|
- $this->assertArrayHasKey('$_p1#start', $listener->nodes); |
| 98 |
|
- $this->assertArrayHasKey('$_p1#end', $listener->nodes); |
|
87 |
+ $visitor->visitPackage($packages->current()); |
|
88 |
+ |
|
89 |
+ $actual = $listener->nodes; |
|
90 |
+ $expected = array( |
|
91 |
+ $codeUri . '#start' => true, |
|
92 |
+ $codeUri . '#end' => true, |
|
93 |
+ 'package#start' => true, |
|
94 |
+ 'package#end' => true, |
|
95 |
+ 'clazz#start' => true, |
|
96 |
+ 'clazz#end' => true, |
|
97 |
+ 'func#start' => true, |
|
98 |
+ 'func#end' => true, |
|
99 |
+ 'interfs#start' => true, |
|
100 |
+ 'interfs#end' => true, |
|
101 |
+ 'm1#start' => true, |
|
102 |
+ 'm1#end' => true, |
|
103 |
+ 'm2#start' => true, |
|
104 |
+ 'm2#end' => true, |
|
105 |
+ 'm3#start' => true, |
|
106 |
+ 'm3#end' => true, |
|
107 |
+ 'm4#start' => true, |
|
108 |
+ 'm4#end' => true, |
|
109 |
+ '$_p1#start' => true, |
|
110 |
+ '$_p1#end' => true, |
|
111 |
+ ); |
|
112 |
+ |
|
113 |
+ ksort($actual); |
|
114 |
+ ksort($expected); |
|
115 |
+ |
|
116 |
+ $this->assertEquals($expected, $actual); |
| 99 |
117 |
} |
| 100 |
118 |
|
| 101 |
119 |
/** |
| 245 |
294 |
|
| 246 |
295 |
$method->accept($visitor); |
| 247 |
296 |
|
| 248 |
|
- $this->assertArrayHasKey(__FUNCTION__ . '#start', $listener->nodes); |
| 249 |
|
- $this->assertArrayHasKey(__FUNCTION__ . '#end', $listener->nodes); |
|
297 |
+ $actual = $listener->nodes; |
|
298 |
+ $expected = array( |
|
299 |
+ __FUNCTION__ . '#start' => true, |
|
300 |
+ __FUNCTION__ . '#end' => true, |
|
301 |
+ ); |
|
302 |
+ |
|
303 |
+ $this->assertEquals($expected, $actual); |
| 250 |
304 |
} |
| 251 |
305 |
|
| 252 |
306 |
/** |
| 253 |
|
- * Tests that the default listener implementation delegates a closure call |
| 254 |
|
- * to the startVisitNode() and endVisitNode() methods. |
|
307 |
+ * testListenerCallsStartVisitNodeForPassedParameterInstance |
| 255 |
308 |
* |
| 256 |
309 |
* @return void |
|
310 |
+ * @covers PHP_Depend_Visitor_AbstractListener |
|
311 |
+ * @group pdepend |
|
312 |
+ * @group pdepend::visitor |
|
313 |
+ * @group unittest |
| 257 |
314 |
*/ |
| 258 |
|
- public function testListenerCallsStartNodeEndNodeForClosure() |
|
315 |
+ public function testListenerCallsStartVisitNodeForPassedParameterInstance() |
| 259 |
316 |
{ |
| 260 |
|
- include_once 'PHP/Depend/Code/Closure.php'; |
|
317 |
+ $listener = $this->getMock('PHP_Depend_Visitor_AbstractListener', array('startVisitNode')); |
|
318 |
+ $listener->expects($this->once()) |
|
319 |
+ ->method('startVisitNode'); |
| 261 |
320 |
|
| 262 |
|
- $closure = $this->getMock('PHP_Depend_Code_Closure', array('getName')); |
| 263 |
|
- $closure->expects($this->atLeastOnce()) |
| 264 |
|
- ->method('getName') |
| 265 |
|
- ->will($this->returnValue(__FUNCTION__)); |
|
321 |
+ $parameter = $this->getMock('PHP_Depend_Code_Parameter', array(), array(null), '', false); |
|
322 |
+ $listener->startVisitParameter($parameter); |
|
323 |
+ } |
| 266 |
324 |
|
| 267 |
|
- $listener = new PHP_Depend_Visitor_TestListener(); |
| 268 |
|
- $visitor = new PHP_Depend_Visitor_DefaultVisitorDummy(); |
| 269 |
|
- $visitor->addVisitListener($listener); |
|
325 |
+ /** |
|
326 |
+ * testListenerCallsEndVisitNodeForPassedParameterInstance |
|
327 |
+ * |
|
328 |
+ * @return void |
|
329 |
+ * @covers PHP_Depend_Visitor_AbstractListener |
|
330 |
+ * @group pdepend |
|
331 |
+ * @group pdepend::visitor |
|
332 |
+ * @group unittest |
|
333 |
+ */ |
|
334 |
+ public function testListenerCallsEndVisitNodeForPassedParameterInstance() |
|
335 |
+ { |
|
336 |
+ $listener = $this->getMock('PHP_Depend_Visitor_AbstractListener', array('endVisitNode')); |
|
337 |
+ $listener->expects($this->once()) |
|
338 |
+ ->method('endVisitNode'); |
| 270 |
339 |
|
| 271 |
|
- $closure->accept($visitor); |
| 272 |
|
- |
| 273 |
|
- $this->assertArrayHasKey(__FUNCTION__ . '#start', $listener->nodes); |
| 274 |
|
- $this->assertArrayHasKey(__FUNCTION__ . '#end', $listener->nodes); |
|
340 |
+ $parameter = $this->getMock('PHP_Depend_Code_Parameter', array(), array(null), '', false); |
|
341 |
+ $listener->endVisitParameter($parameter); |
| 275 |
342 |
} |
| 276 |
|
-} |
|
343 |
+} |
| 91 |
91 |
$expected = array( |
| 92 |
92 |
'pkgA', |
| 93 |
93 |
'classB', |
| 94 |
|
- $codeUri, |
|
94 |
+ 'PHP_Depend_Code_File', |
| 95 |
95 |
'methodBA', |
| 96 |
96 |
'methodBB', |
| 97 |
97 |
'classA', |
| 98 |
|
- $codeUri, |
|
98 |
+ 'PHP_Depend_Code_File', |
| 99 |
99 |
'methodAB', |
| 100 |
100 |
'methodAA', |
| 101 |
101 |
'pkgB', |
| 102 |
102 |
'interfsC', |
| 103 |
|
- $codeUri, |
|
103 |
+ 'PHP_Depend_Code_File', |
| 104 |
104 |
'methodCB', |
| 105 |
105 |
'methodCA', |
| 106 |
106 |
'funcD', |
| 107 |
|
- $codeUri |
|
107 |
+ 'PHP_Depend_Code_File' |
| 108 |
108 |
); |
| 109 |
109 |
|
| 110 |
110 |
$this->assertEquals($expected, $visitor->visits); |
| 111 |
111 |
} |
| 112 |
112 |
|
| 113 |
113 |
/** |
| 114 |
|
- * Tests that the default visitor implementation emits the expected signals |
| 115 |
|
- * for a closure. |
|
114 |
+ * testVisitorVisitsFunctionParameter |
|
115 |
+ * |
|
116 |
+ * @return void |
|
117 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
118 |
+ * @group pdepend |
|
119 |
+ * @group pdepend::visitor |
|
120 |
+ * @group unittest |
|
121 |
+ */ |
|
122 |
+ public function testVisitorVisitsFunctionParameter() |
|
123 |
+ { |
|
124 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
125 |
+ |
|
126 |
+ $visitor = $this->getMock('PHP_Depend_Visitor_AbstractVisitor', array('visitParameter')); |
|
127 |
+ $visitor->expects($this->exactly(2)) |
|
128 |
+ ->method('visitParameter'); |
|
129 |
+ |
|
130 |
+ $visitor->visitPackage($packages->current()); |
|
131 |
+ } |
|
132 |
+ |
|
133 |
+ /** |
|
134 |
+ * testVisitorVisitsMethodParameter |
| 116 |
135 |
* |
| 117 |
136 |
* @return void |
|
137 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
138 |
+ * @group pdepend |
|
139 |
+ * @group pdepend::visitor |
|
140 |
+ * @group unittest |
| 118 |
141 |
*/ |
| 119 |
|
- public function testClosureHandlerEmitExpectedListenerSignal() |
|
142 |
+ public function testVisitorVisitsMethodParameter() |
| 120 |
143 |
{ |
| 121 |
|
- include_once 'PHP/Depend/Code/Closure.php'; |
| 122 |
|
- include_once 'PHP/Depend/Visitor/ListenerI.php'; |
|
144 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
| 123 |
145 |
|
|
146 |
+ $visitor = $this->getMock('PHP_Depend_Visitor_AbstractVisitor', array('visitParameter')); |
|
147 |
+ $visitor->expects($this->exactly(3)) |
|
148 |
+ ->method('visitParameter'); |
|
149 |
+ |
|
150 |
+ $visitor->visitPackage($packages->current()); |
|
151 |
+ } |
|
152 |
+ |
|
153 |
+ /** |
|
154 |
+ * testVisitorInvokesStartVisitParameterOnListener |
|
155 |
+ * |
|
156 |
+ * @return void |
|
157 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
158 |
+ * @group pdepend |
|
159 |
+ * @group pdepend::visitor |
|
160 |
+ * @group unittest |
|
161 |
+ */ |
|
162 |
+ public function testVisitorInvokesStartVisitParameterOnListener() |
|
163 |
+ { |
|
164 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
165 |
+ |
| 124 |
166 |
$listener = $this->getMock('PHP_Depend_Visitor_ListenerI'); |
| 125 |
|
- $listener->expects($this->at(0)) |
| 126 |
|
- ->method('startVisitClosure'); |
| 127 |
|
- $listener->expects($this->at(1)) |
| 128 |
|
- ->method('endVisitClosure'); |
|
167 |
+ $listener->expects($this->exactly(2)) |
|
168 |
+ ->method('startVisitParameter'); |
| 129 |
169 |
|
| 130 |
|
- $closure = $this->getMock('PHP_Depend_Code_Closure'); |
|
170 |
+ $visitor = $this->getMockForAbstractClass('PHP_Depend_Visitor_AbstractVisitor'); |
|
171 |
+ $visitor->addVisitListener($listener); |
| 131 |
172 |
|
| 132 |
|
- $visitor = new PHP_Depend_Visitor_DefaultVisitorDummy(); |
|
173 |
+ $visitor->visitPackage($packages->current()); |
|
174 |
+ } |
|
175 |
+ |
|
176 |
+ /** |
|
177 |
+ * testVisitorInvokesEndVisitParameterOnListener |
|
178 |
+ * |
|
179 |
+ * @return void |
|
180 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
181 |
+ * @group pdepend |
|
182 |
+ * @group pdepend::visitor |
|
183 |
+ * @group unittest |
|
184 |
+ */ |
|
185 |
+ public function testVisitorInvokesEndVisitParameterOnListener() |
|
186 |
+ { |
|
187 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
188 |
+ |
|
189 |
+ $listener = $this->getMock('PHP_Depend_Visitor_ListenerI'); |
|
190 |
+ $listener->expects($this->exactly(3)) |
|
191 |
+ ->method('endVisitParameter'); |
|
192 |
+ |
|
193 |
+ $visitor = $this->getMockForAbstractClass('PHP_Depend_Visitor_AbstractVisitor'); |
| 133 |
194 |
$visitor->addVisitListener($listener); |
| 134 |
|
- $visitor->visitClosure($closure); |
|
195 |
+ |
|
196 |
+ $visitor->visitPackage($packages->current()); |
| 135 |
197 |
} |
| 136 |
198 |
|
|
199 |
+ /** |
|
200 |
+ * testVisitorInvokesStartVisitInterfaceOnListener |
|
201 |
+ * |
|
202 |
+ * @return void |
|
203 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
204 |
+ * @group pdepend |
|
205 |
+ * @group pdepend::visitor |
|
206 |
+ * @group unittest |
|
207 |
+ */ |
|
208 |
+ public function testVisitorInvokesStartVisitInterfaceOnListener() |
|
209 |
+ { |
|
210 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
211 |
+ |
|
212 |
+ $listener = $this->getMock('PHP_Depend_Visitor_ListenerI'); |
|
213 |
+ $listener->expects($this->once()) |
|
214 |
+ ->method('startVisitInterface'); |
|
215 |
+ |
|
216 |
+ $visitor = $this->getMockForAbstractClass('PHP_Depend_Visitor_AbstractVisitor'); |
|
217 |
+ $visitor->addVisitListener($listener); |
|
218 |
+ |
|
219 |
+ $visitor->visitPackage($packages->current()); |
|
220 |
+ } |
|
221 |
+ |
|
222 |
+ /** |
|
223 |
+ * testVisitorInvokesEndVisitInterfaceOnListener |
|
224 |
+ * |
|
225 |
+ * @return void |
|
226 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
227 |
+ * @group pdepend |
|
228 |
+ * @group pdepend::visitor |
|
229 |
+ * @group unittest |
|
230 |
+ */ |
|
231 |
+ public function testVisitorInvokesEndVisitInterfaceOnListener() |
|
232 |
+ { |
|
233 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
234 |
+ |
|
235 |
+ $listener = $this->getMock('PHP_Depend_Visitor_ListenerI'); |
|
236 |
+ $listener->expects($this->once()) |
|
237 |
+ ->method('endVisitInterface'); |
|
238 |
+ |
|
239 |
+ $visitor = $this->getMockForAbstractClass('PHP_Depend_Visitor_AbstractVisitor'); |
|
240 |
+ $visitor->addVisitListener($listener); |
|
241 |
+ |
|
242 |
+ $visitor->visitPackage($packages->current()); |
|
243 |
+ } |
|
244 |
+ |
|
245 |
+ /** |
|
246 |
+ * testVisitorInvokesStartVisitPropertyOnListener |
|
247 |
+ * |
|
248 |
+ * @return void |
|
249 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
250 |
+ * @group pdepend |
|
251 |
+ * @group pdepend::visitor |
|
252 |
+ * @group unittest |
|
253 |
+ */ |
|
254 |
+ public function testVisitorInvokesStartVisitPropertyOnListener() |
|
255 |
+ { |
|
256 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
257 |
+ |
|
258 |
+ $listener = $this->getMock('PHP_Depend_Visitor_ListenerI'); |
|
259 |
+ $listener->expects($this->once()) |
|
260 |
+ ->method('startVisitProperty'); |
|
261 |
+ |
|
262 |
+ $visitor = $this->getMockForAbstractClass('PHP_Depend_Visitor_AbstractVisitor'); |
|
263 |
+ $visitor->addVisitListener($listener); |
|
264 |
+ |
|
265 |
+ $visitor->visitPackage($packages->current()); |
|
266 |
+ } |
|
267 |
+ |
|
268 |
+ /** |
|
269 |
+ * testVisitorInvokesEndVisitPropertyOnListener |
|
270 |
+ * |
|
271 |
+ * @return void |
|
272 |
+ * @covers PHP_Depend_Visitor_AbstractVisitor |
|
273 |
+ * @group pdepend |
|
274 |
+ * @group pdepend::visitor |
|
275 |
+ * @group unittest |
|
276 |
+ */ |
|
277 |
+ public function testVisitorInvokesEndVisitPropertyOnListener() |
|
278 |
+ { |
|
279 |
+ $packages = self::parseTestCaseSource(__METHOD__); |
|
280 |
+ |
|
281 |
+ $listener = $this->getMock('PHP_Depend_Visitor_ListenerI'); |
|
282 |
+ $listener->expects($this->once()) |
|
283 |
+ ->method('endVisitProperty'); |
|
284 |
+ |
|
285 |
+ $visitor = $this->getMockForAbstractClass('PHP_Depend_Visitor_AbstractVisitor'); |
|
286 |
+ $visitor->addVisitListener($listener); |
|
287 |
+ |
|
288 |
+ $visitor->visitPackage($packages->current()); |
|
289 |
+ } |
| 137 |
290 |
} |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category PHP |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Bugs |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://www.pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once dirname(__FILE__) . '/AbstractTest.php'; |
|
51 |
+ |
|
52 |
+/** |
|
53 |
+ * Test case for bug #152. |
|
54 |
+ * |
|
55 |
+ * @category PHP |
|
56 |
+ * @package PHP_Depend |
|
57 |
+ * @subpackage Bugs |
|
58 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
59 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
60 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
61 |
+ * @version Release: @package_version@ |
|
62 |
+ * @link http://www.pdepend.org/ |
|
63 |
+ */ |
|
64 |
+class PHP_Depend_Bugs_EndLessLoopBetweenForParentClassBug152Test |
|
65 |
+ extends PHP_Depend_Bugs_AbstractTest |
|
66 |
+{ |
|
67 |
+ /** |
|
68 |
+ * testClassNotResultsInEndlessLoopWhileCallingGetParentClass |
|
69 |
+ * |
|
70 |
+ * @return void |
|
71 |
+ * @covers stdClass |
|
72 |
+ * @group pdepend |
|
73 |
+ * @group pdepend::bugs |
|
74 |
+ * @group regressiontest |
|
75 |
+ */ |
|
76 |
+ public function testClassNotResultsInEndlessLoopWhileCallingGetParentClass() |
|
77 |
+ { |
|
78 |
+ self::parseTestCaseSource(__METHOD__) |
|
79 |
+ ->current() |
|
80 |
+ ->getClasses() |
|
81 |
+ ->current() |
|
82 |
+ ->getInterfaces(); |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ /** |
|
86 |
+ * testClassNotResultsInEndlessLoopWhileCallingGetInterfaces |
|
87 |
+ * |
|
88 |
+ * @return void |
|
89 |
+ * @covers stdClass |
|
90 |
+ * @group pdepend |
|
91 |
+ * @group pdepend::bugs |
|
92 |
+ * @group regressiontest |
|
93 |
+ */ |
|
94 |
+ public function testClassNotResultsInEndlessLoopWhileCallingGetInterfaces() |
|
95 |
+ { |
|
96 |
+ self::parseTestCaseSource(__METHOD__) |
|
97 |
+ ->current() |
|
98 |
+ ->getClasses() |
|
99 |
+ ->current() |
|
100 |
+ ->getInterfaces(); |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+ /** |
|
104 |
+ * testClassDeclarationAndParameterTypeHintAreReferencesToTheSameClass |
|
105 |
+ * |
|
106 |
+ * @return void |
|
107 |
+ * @covers stdClass |
|
108 |
+ * @group pdepend |
|
109 |
+ * @group pdepend::bugs |
|
110 |
+ * @group regressiontest |
|
111 |
+ */ |
|
112 |
+ public function testClassDeclarationAndParameterTypeHintAreReferencesToTheSameClass() |
|
113 |
+ { |
|
114 |
+ $class = self::parseTestCaseSource(__METHOD__) |
|
115 |
+ ->current() |
|
116 |
+ ->getClasses() |
|
117 |
+ ->current(); |
|
118 |
+ |
|
119 |
+ $typeHint = $class->getMethods() |
|
120 |
+ ->current() |
|
121 |
+ ->getParameters() |
|
122 |
+ ->current() |
|
123 |
+ ->getClass(); |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ /** |
|
127 |
+ * testParserDoesNotDetectThrownInternalExceptionClassAsPartOfPackage |
|
128 |
+ * |
|
129 |
+ * @return void |
|
130 |
+ * @covers stdClass |
|
131 |
+ * @group pdepend |
|
132 |
+ * @group pdepend::bugs |
|
133 |
+ * @group regressiontest |
|
134 |
+ * @group barbaz |
|
135 |
+ */ |
|
136 |
+ public function testParserDoesNotDetectThrownInternalExceptionClassAsPartOfPackage() |
|
137 |
+ { |
|
138 |
+ $classes = self::parseTestCaseSource(__METHOD__) |
|
139 |
+ ->current() |
|
140 |
+ ->getClasses(); |
|
141 |
+ |
|
142 |
+ $this->assertEquals(1, count($classes)); |
|
143 |
+ } |
|
144 |
+} |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category PHP |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Bugs |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://www.pdepend.org/ |
|
48 |
+ */ |
|
49 |
+ |
|
50 |
+require_once dirname(__FILE__) . '/AbstractTest.php'; |
|
51 |
+ |
|
52 |
+/** |
|
53 |
+ * Test case for ticket #114. |
|
54 |
+ * |
|
55 |
+ * @category PHP |
|
56 |
+ * @package PHP_Depend |
|
57 |
+ * @subpackage Bugs |
|
58 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
59 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
60 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
61 |
+ * @version Release: @package_version@ |
|
62 |
+ * @link http://www.pdepend.org/ |
|
63 |
+ */ |
|
64 |
+class PHP_Depend_Bugs_ComplexStringParsingBug114Test extends PHP_Depend_Bugs_AbstractTest |
|
65 |
+{ |
|
66 |
+ /** |
|
67 |
+ * testParserHandlesStringWithEmbeddedBacktickExpression |
|
68 |
+ * |
|
69 |
+ * @return void |
|
70 |
+ * @covers stdClass |
|
71 |
+ * @group pdepend |
|
72 |
+ * @group pdepend::bugs |
|
73 |
+ * @group regressiontest |
|
74 |
+ */ |
|
75 |
+ public function testParserHandlesStringWithEmbeddedBacktickExpression() |
|
76 |
+ { |
|
77 |
+ self::parseTestCaseSource(__METHOD__); |
|
78 |
+ } |
|
79 |
+ |
|
80 |
+ /** |
|
81 |
+ * testParserHandlesStringWithEmbeddedExpression |
|
82 |
+ * |
|
83 |
+ * @return void |
|
84 |
+ * @covers stdClass |
|
85 |
+ * @group pdepend |
|
86 |
+ * @group pdepend::bugs |
|
87 |
+ * @group regressiontest |
|
88 |
+ */ |
|
89 |
+ public function testParserHandlesStringWithEmbeddedExpression() |
|
90 |
+ { |
|
91 |
+ self::parseTestCaseSource(__METHOD__); |
|
92 |
+ } |
|
93 |
+ |
|
94 |