Arbit - project tracking

PHP Depend

History

Diff

1030 1032 /catalog.xml
2 -<?xml version="1.0" encoding="UTF-8" standalone="no"?>
3 -<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
4 - <nextCatalog catalog="nbproject/private/cache/retriever/catalog.xml"/>
5 -</catalog>
1030 1032 /tests/PHP/Depend/AllTests.php
56 56 require_once dirname(__FILE__) . '/AbstractTest.php';
57 57 require_once dirname(__FILE__) . '/DependTest.php';
58 58 require_once dirname(__FILE__) . '/ParserTest.php';
59 +require_once dirname(__FILE__) . '/ParserRegressionTest.php';
59 60 require_once dirname(__FILE__) . '/StorageRegistryTest.php';
60 61 require_once dirname(__FILE__) . '/Builder/DefaultTest.php';
61 62 require_once dirname(__FILE__) . '/Bugs/AllTests.php';
64 65 require_once dirname(__FILE__) . '/Issues/AllTests.php';
65 66 require_once dirname(__FILE__) . '/Log/AllTests.php';
66 67 require_once dirname(__FILE__) . '/Metrics/AllTests.php';
68 +require_once dirname(__FILE__) . '/Parser/AllTests.php';
67 69 require_once dirname(__FILE__) . '/TextUI/AllTests.php';
68 70 require_once dirname(__FILE__) . '/Tokenizer/AllTests.php';
69 71 require_once dirname(__FILE__) . '/Util/AllTests.php';
107 109 $suite->addTest(PHP_Depend_Log_AllTests::suite());
108 110 $suite->addTest(PHP_Depend_Input_AllTests::suite());
109 111 $suite->addTest(PHP_Depend_Metrics_AllTests::suite());
112 + $suite->addTest(PHP_Depend_Parser_AllTests::suite());
110 113 $suite->addTest(PHP_Depend_TextUI_AllTests::suite());
111 114 $suite->addTest(PHP_Depend_Tokenizer_AllTests::suite());
112 115 $suite->addTest(PHP_Depend_Util_AllTests::suite());
114 117
115 118 $suite->addTestSuite('PHP_Depend_Builder_DefaultTest');
116 119 $suite->addTestSuite('PHP_Depend_ParserTest');
120 + $suite->addTestSuite('PHP_Depend_ParserRegressionTest');
117 121 $suite->addTestSuite('PHP_Depend_DependTest');
118 122 $suite->addTestSuite('PHP_Depend_StorageRegistryTest');
119 123
1030 1032 /tests/PHP/Depend/Log/DummyAnalyzer.php
148 148 public function analyze(PHP_Depend_Code_NodeIterator $packages)
149 149 {
150 150 }
151 -
151 +
152 + /**
153 + * By default all analyzers are enabled. Overwrite this method to provide
154 + * state based disabling/enabling.
155 + *
156 + * @return boolean
157 + * @since 0.9.10
158 + */
159 + public function isEnabled()
160 + {
161 + return true;
162 + }
152 163 }
1030 1032 /tests/PHP/Depend/Log/Phpunit/_expected/phpunit-log.xml
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>
1030 1032 /tests/PHP/Depend/Log/Phpunit/XmlTest.php
146 146 * Tests the result of the phpunit logger with some real analyzers.
147 147 *
148 148 * @return void
149 + * @covers PHP_Depend_Log_Phpunit_Xml
150 + * @group pdepend
151 + * @group pdepend::logs
152 + * @group pdepend::logs::summary
153 + * @group unittest
149 154 */
150 155 public function testPHPUnitLoggerResult()
151 156 {
152 - $packages = self::parseSource('log/phpunit');
157 + $packages = self::parseTestCaseSource(__METHOD__);
153 158
154 159 $logger = new PHP_Depend_Log_Phpunit_Xml();
155 160 $logger->setLogFile($this->_tempFile);
191 196
192 197 $logger->close();
193 198
194 - $this->assertFileExists($this->_tempFile);
195 -
196 199 $actual = file_get_contents($this->_tempFile);
197 200 $expected = $this->_loadExpected('phpunit-log.xml');
198 201
200 203 }
201 204
202 205 /**
206 + * testPHPUnitLogNotContainsNotUserDefinedClasses
207 + *
208 + * @return void
209 + * @covers PHP_Depend_Log_Phpunit_Xml
210 + * @group pdepend
211 + * @group pdepend::logs
212 + * @group pdepend::logs::summary
213 + * @group unittest
214 + */
215 + public function testPHPUnitLogNotContainsNotUserDefinedClasses()
216 + {
217 + $logger = new PHP_Depend_Log_Phpunit_Xml();
218 + $logger->setLogFile($this->_tempFile);
219 + $logger->setCode(self::parseTestCaseSource(__METHOD__));
220 + $logger->close();
221 +
222 + $sxml = simplexml_load_file($this->_tempFile);
223 + $this->assertEquals(array(), $sxml->xpath('//class[@name="' . __FUNCTION__ . 'Parent"]'));
224 + }
225 +
226 + /**
203 227 * Loads the expected log file and adjusts the file@name attribute.
204 228 *
205 229 * @param string $file The log file name.
1030 1032 /tests/PHP/Depend/Log/Jdepend/XmlTest.php
97 97 {
98 98 parent::setUp();
99 99
100 - // Configure the filter collection
101 - $collection = PHP_Depend_Code_Filter_Collection::getInstance();
102 - $collection->addFilter(new PHP_Depend_Code_Filter_DefaultPackage());
103 - $collection->addFilter(new PHP_Depend_Code_Filter_InternalPackage());
104 -
105 100 $this->packages = self::parseSource(dirname(__FILE__) . '/../../_code/code-5.2.x');
106 101
107 - $collection->clear();
108 -
109 102 $this->analyzer = new PHP_Depend_Metrics_Dependency_Analyzer();
110 103 $this->analyzer->analyze($this->packages);
111 104
119 112 */
120 113 protected function tearDown()
121 114 {
122 - // Clear filter collection
123 - $collection = PHP_Depend_Code_Filter_Collection::getInstance();
124 - $collection->clear();
125 -
126 115 @unlink($this->resultFile);
127 116
128 117 parent::tearDown();
1030 1032 /tests/PHP/Depend/Log/Jdepend/ChartTest.php
71 71 class PHP_Depend_Log_Jdepend_ChartTest extends PHP_Depend_AbstractTest
72 72 {
73 73 /**
74 + * Temporary output file.
75 + *
76 + * @var string
77 + */
78 + private $_outputFile = null;
79 +
80 + /**
81 + * setUp()
82 + *
83 + * @return void
84 + */
85 + protected function setUp()
86 + {
87 + parent::setUp();
88 +
89 + $this->_outputFile = self::createRunResourceURI('jdepend-test-out.svg');
90 + if (file_exists($this->_outputFile)) {
91 + unlink($this->_outputFile);
92 + }
93 + }
94 +
95 + /**
96 + * tearDown()
97 + *
98 + * @return void
99 + */
100 + protected function tearDown()
101 + {
102 + if (file_exists($this->_outputFile)) {
103 + unlink($this->_outputFile);
104 + }
105 + parent::tearDown();
106 + }
107 +
108 +
109 + /**
74 110 * Tests that the logger returns the expected set of analyzers.
75 111 *
76 112 * @return void
113 + * @covers PHP_Depend_Log_Jdepend_Chart
114 + * @group pdepend
115 + * @group pdepend::log
116 + * @group pdepend::log::jdepend
117 + * @group unittest
77 118 */
78 119 public function testReturnsExceptedAnalyzers()
79 120 {
89 130 * configured.
90 131 *
91 132 * @return void
133 + * @covers PHP_Depend_Log_Jdepend_Chart
134 + * @group pdepend
135 + * @group pdepend::log
136 + * @group pdepend::log::jdepend
137 + * @group unittest
138 + * @expectedException PHP_Depend_Log_NoLogOutputException
92 139 */
93 140 public function testThrowsExceptionForInvalidLogTarget()
94 141 {
95 - $this->setExpectedException(
96 - 'PHP_Depend_Log_NoLogOutputException',
97 - "The log target is not configured for 'PHP_Depend_Log_Jdepend_Chart'."
98 - );
99 -
100 142 $logger = new PHP_Depend_Log_Jdepend_Chart();
101 143 $logger->close();
102 144 }
103 145
146 + /**
147 + * testChartLogAcceptsOnlyTheCorrectAnalyzer
148 + *
149 + * @return void
150 + * @covers PHP_Depend_Log_Jdepend_Chart
151 + * @group pdepend
152 + * @group pdepend::log
153 + * @group pdepend::log::jdepend
154 + * @group unittest
155 + */
104 156 public function testChartLogAcceptsOnlyTheCorrectAnalyzer()
105 157 {
106 158 $logger = new PHP_Depend_Log_Jdepend_Chart();
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 {
228 333 unlink($fileName);
229 334 }
230 335
231 - $nodes = new PHP_Depend_Code_NodeIterator(array(
232 - new PHP_Depend_Code_Package('packageA'),
233 - new PHP_Depend_Code_Package('packageB')
234 - ));
336 + $nodes = new PHP_Depend_Code_NodeIterator($this->_createPackages(true, true));
235 337
236 338 $analyzer = new PHP_Depend_Metrics_Dependency_Analyzer();
237 339 $analyzer->analyze($nodes);
253 355
254 356 unlink($fileName);
255 357 }
358 +
359 + private function _createPackages()
360 + {
361 + $packages = array();
362 + foreach (func_get_args() as $i => $userDefined) {
363 + $packages[] = $this->_createPackage(
364 + $userDefined,
365 + 'package' . $i
366 + );
367 + }
368 + return $packages;
369 + }
370 +
371 + private function _createPackage($userDefined, $packageName)
372 + {
373 + $packageA = $this->getMock(
374 + 'PHP_Depend_Code_Package',
375 + array('isUserDefined'),
376 + array($packageName),
377 + 'package_' . md5(microtime())
378 + );
379 + $packageA->expects($this->atLeastOnce())
380 + ->method('isUserDefined')
381 + ->will($this->returnValue($userDefined));
382 +
383 + return $packageA;
384 + }
256 385 }
1030 1032 /tests/PHP/Depend/Log/Summary/_expected/xml-log-without-metrics.xml
19 19 <file name="???"/>
20 20 </function>
21 21 </package>
22 - <package name="pkg2"/>
23 22 <package name="pkg3">
24 23 <class name="Bar">
25 24 <file name="???"/>
1030 1032 /tests/PHP/Depend/Log/Summary/_expected/node-aware-result-set.xml
19 19 <file name="???"/>
20 20 </function>
21 21 </package>
22 - <package name="pkg2" loc="3" ncloc="3"/>
23 22 <package name="pkg3" loc="42" ncloc="23">
24 23 <class name="Bar" loc="33" ncloc="20">
25 24 <file name="???"/>
1030 1032 /tests/PHP/Depend/Log/Summary/_expected/node-and-project-aware-result-set.xml
2 +<?xml version="1.0" encoding="UTF-8"?>
3 +<metrics generated="2009-07-27T18:00:36" pdepend="@package_version@" bar="23" foo="42">
4 + <files>
5 + <file name="???" baz="23" foobar="42"/>
6 + </files>
7 + <package name="+global" baz="23" foobar="42">
8 + <function name="bar" baz="23" foobar="42">
9 + <file name="???"/>
10 + </function>
11 + </package>
12 + <package name="pkg1" baz="23" foobar="42">
13 + <class name="FooBar" baz="23" foobar="42">
14 + <file name="???"/>
15 + <method name="x" baz="23" foobar="42"/>
16 + <method name="y" baz="23" foobar="42"/>
17 + </class>
18 + <function name="foo" baz="23" foobar="42">
19 + <file name="???"/>
20 + </function>
21 + </package>
22 + <package name="pkg3" baz="23" foobar="42">
23 + <class name="Bar" baz="23" foobar="42">
24 + <file name="???"/>
25 + <method name="y" baz="23" foobar="42"/>
26 + </class>
27 + </package>
28 +</metrics>
1030 1032 /tests/PHP/Depend/Log/Summary/XmlTest.php
50 50 require_once dirname(__FILE__) . '/../../AbstractTest.php';
51 51 require_once dirname(__FILE__) . '/AnalyzerNodeAwareDummy.php';
52 52 require_once dirname(__FILE__) . '/AnalyzerProjectAwareDummy.php';
53 +require_once dirname(__FILE__) . '/AnalyzerNodeAndProjectAwareDummy.php';
53 54
54 -require_once 'PHP/Depend/Parser.php';
55 -require_once 'PHP/Depend/Builder/Default.php';
56 -require_once 'PHP/Depend/Tokenizer/Internal.php';
57 55 require_once 'PHP/Depend/Log/Summary/Xml.php';
56 +require_once 'PHP/Depend/Metrics/NodeAwareI.php';
57 +require_once 'PHP/Depend/Metrics/ProjectAwareI.php';
58 58
59 59 /**
60 60 * Test case for the xml summary log.
154 154 }
155 155
156 156 /**
157 + * testLogMethodReturnsTrueForAnalyzerOfTypeProjectAware
158 + *
159 + * @return void
160 + * @covers PHP_Depend_Log_Summary_Xml
161 + * @group pdepend
162 + * @group pdepend::logs
163 + * @group pdepend::logs::summary
164 + * @group unittest
165 + */
166 + public function testLogMethodReturnsTrueForAnalyzerOfTypeProjectAware()
167 + {
168 + $logger = new PHP_Depend_Log_Summary_Xml();
169 + $actual = $logger->log($this->getMock('PHP_Depend_Metrics_ProjectAwareI'));
170 +
171 + $this->assertTrue($actual);
172 + }
173 +
174 + /**
175 + * testLogMethodReturnsTrueForAnalyzerOfTypeNodeAware
176 + *
177 + * @return void
178 + * @covers PHP_Depend_Log_Summary_Xml
179 + * @group pdepend
180 + * @group pdepend::logs
181 + * @group pdepend::logs::summary
182 + * @group unittest
183 + */
184 + public function testLogMethodReturnsTrueForAnalyzerOfTypeNodeAware()
185 + {
186 + $logger = new PHP_Depend_Log_Summary_Xml();
187 + $actual = $logger->log($this->getMock('PHP_Depend_Metrics_NodeAwareI'));
188 +
189 + $this->assertTrue($actual);
190 + }
191 +
192 + /**
157 193 * Tests that {@link PHP_Depend_Log_Summary_Xml::write()} generates the
158 194 * expected document structure for the source, but without any applied
159 195 * metrics.
170 206 $fileName = 'xml-log-without-metrics.xml';
171 207 $this->assertXmlStringEqualsXmlString(
172 208 $this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"),
173 - file_get_contents($this->resultFile)
209 + $this->getNormalizedPathXml($this->resultFile)
174 210 );
175 211 }
176 212
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(
244 311 $log = new PHP_Depend_Log_Summary_Xml();
245 312 $log->setLogFile($this->resultFile);
246 313 $log->setCode($this->packages);
247 - $this->assertTrue($log->log($resultOne));
248 - $this->assertTrue($log->log($resultTwo));
314 + $log->log($resultOne);
315 + $log->log($resultTwo);
249 316
250 317 $log->close();
251 318
252 319 $fileName = 'node-aware-result-set.xml';
253 320 $this->assertXmlStringEqualsXmlString(
254 321 $this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"),
255 - file_get_contents($this->resultFile)
322 + $this->getNormalizedPathXml($this->resultFile)
256 323 );
257 324 }
258 325
266 333 foreach ($dom->getElementsByTagName('file') as $file) {
267 334 $file->setAttribute('name', $this->testFileName);
268 335 }
336 + $dom->documentElement->setAttribute('generated', '2010-02-22T08:26:51');
269 337
270 - $dom->documentElement->setAttribute('generated', date('Y-m-d\TH:i:s'));
271 -
272 338 return $dom->saveXML();
273 339 }
274 340 }
1030 1032 /tests/PHP/Depend/Log/Summary/AnalyzerNodeAndProjectAwareDummy.php
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 +}
1030 1032 /tests/PHP/Depend/Log/Summary/AnalyzerNodeAwareDummy.php
115 115 }
116 116
117 117 /**
118 + * By default all analyzers are enabled. Overwrite this method to provide
119 + * state based disabling/enabling.
120 + *
121 + * @return boolean
122 + * @since 0.9.10
123 + */
124 + public function isEnabled()
125 + {
126 + return true;
127 + }
128 +
129 + /**
118 130 * Returns an array with metrics for the requested node.
119 131 *
120 132 * @param PHP_Depend_Code_NodeI $node The context node instance.
1030 1032 /tests/PHP/Depend/Log/Summary/AnalyzerProjectAwareDummy.php
115 115 }
116 116
117 117 /**
118 + * By default all analyzers are enabled. Overwrite this method to provide
119 + * state based disabling/enabling.
120 + *
121 + * @return boolean
122 + * @since 0.9.10
123 + */
124 + public function isEnabled()
125 + {
126 + return true;
127 + }
128 +
129 + /**
118 130 * Returns the project metrics.
119 131 *
120 132 * @return array(string=>mixed)
1030 1032 /tests/PHP/Depend/ParserTest.php
42 42 * @author Manuel Pichler <mapi@pdepend.org>
43 43 * @copyright 2008-2010 Manuel Pichler. All rights reserved.
44 44 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
45 - * @version SVN: $Id: ParserTest.php 673 2009-03-04 21:39:16Z mapi $
45 + * @version SVN: $Id$
46 46 * @link http://pdepend.org/
47 47 */
48 48
66 66 class PHP_Depend_ParserTest extends PHP_Depend_AbstractTest
67 67 {
68 68 /**
69 + * testParserHandlesMaxNestingLevel
70 + *
71 + * @return void
72 + * @covers PHP_Depend_Parser
73 + * @group pdepend
74 + * @group pdepend::parser
75 + * @group unittest
76 + */
77 + public function testParserHandlesMaxNestingLevel()
78 + {
79 + if (version_compare(phpversion(), '5.2.10') < 0) {
80 + $this->markTestSkipped();
81 + }
82 +
83 + ini_set('xdebug.max_nesting_level', '100');
84 +
85 + $builder = new PHP_Depend_Builder_Default();
86 +
87 + $tokenizer = new PHP_Depend_Tokenizer_Internal();
88 + $tokenizer->setSourceFile(self::createCodeResourceURI('parser/' . __FUNCTION__ . '.php'));
89 +
90 + $parser = new PHP_Depend_Parser($tokenizer, $builder);
91 + $parser->setMaxNestingLevel(512);
92 + $parser->parse();
93 + }
94 +
95 + /**
69 96 * Tests the main parse method.
70 97 *
71 98 * @return void
73 100 public function testParseMixedCode()
74 101 {
75 102 $expected = array(
76 - 'pkg1' => true,
77 - 'pkg2' => true,
78 - 'pkg3' => true,
103 + 'pkg1' => true,
104 + 'pkg2' => true,
105 + 'pkg3' => true,
79 106 PHP_Depend_BuilderI::DEFAULT_PACKAGE => true
80 107 );
81 108
472 499 * Tests that the parser handles PHP 5.3 object namespace + class chaining.
473 500 *
474 501 * @return void
502 + * @covers PHP_Depend_Parser
503 + * @group pdepend
504 + * @group pdepend::parser
505 + * @group unittest
475 506 */
476 507 public function testParserParseNewInstancePHP53()
477 508 {
478 - $packages = self::parseSource('php-5.3/new.txt');
509 + $packages = self::parseTestCaseSource();
479 510 $function = $packages->current()
480 511 ->getFunctions()
481 512 ->current();
1049 1080 }
1050 1081
1051 1082 /**
1083 + * testParserStripsCommentsInParseExpressionUntilCorrect
1084 + *
1085 + * @return void
1086 + * @covers PHP_Depend_Parser
1087 + * @group pdepend
1088 + * @group pdepend::parser
1089 + * @group unittest
1090 + */
1091 + public function testParserStripsCommentsInParseExpressionUntilCorrect()
1092 + {
1093 + $packages = self::parseSource('parser/' . __FUNCTION__ . '.php');
1094 + $method = $packages->current()
1095 + ->getClasses()
1096 + ->current()
1097 + ->getMethods()
1098 + ->current();
1099 +
1100 + $foreach = $method->getFirstChildOfType(PHP_Depend_Code_ASTForeachStatement::CLAZZ);
1101 + $this->assertNotNull($foreach);
1102 + }
1103 +
1104 + /**
1052 1105 * Tests that the parser throws an exception for an unclosed array
1053 1106 * declaration within the default value of a parameter.
1054 1107 *
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
1443 1807 array(PHP_Depend_TokenizerI::T_CURLY_BRACE_CLOSE, 34),
1444 1808 );
1445 1809
1810 + $actual = array();
1446 1811 foreach ($testClass->getTokens() as $token) {
1447 - $expectedToken = array_shift($expected);
1448 -
1449 - $this->assertNotNull($expectedToken);
1450 - $this->assertEquals($expectedToken[0], $token->type, 'Expected on line: ' . $expectedToken[1]);
1812 + $actual[] = array($token->type, $token->startLine);
1451 1813 }
1452 -
1453 - $this->assertSame(0, count($expected));
1814 + $this->assertSame($expected, $actual);
1454 1815 }
1455 1816
1456 1817 /**
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
1030 1032 /tests/PHP/Depend/TextUI/RunnerTest.php
71 71 * directory.
72 72 *
73 73 * @return void
74 + * @covers PHP_Depend_TextUI_Runner
75 + * @group pdepend
76 + * @group pdepend::textui
77 + * @group unittest
74 78 */
75 79 public function testRunnerThrowsRuntimeExceptionForInvalidSourceDirectory()
76 80 {
90 94 * Tests that the runner stops processing if no logger is specified.
91 95 *
92 96 * @return void
97 + * @covers PHP_Depend_TextUI_Runner
98 + * @group pdepend
99 + * @group pdepend::textui
100 + * @group unittest
93 101 */
94 102 public function testRunnerThrowsRuntimeExceptionIfNoLoggerIsSpecified()
95 103 {
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 +}
1030 1032 /tests/PHP/Depend/TextUI/_files/clover.xml
2 +<?xml version="1.0" encoding="UTF-8"?>
3 +<coverage generated="1265694896" phpunit="3.4.10">
4 + <project name="org::pdepend::reflection::AllTests" timestamp="1265694896">
5 + <package name="pdepend\reflection">
6 + <file name="/tmp">
7 + </file>
8 + </package>
9 + </project>
10 +</coverage>
1030 1032 /tests/PHP/Depend/TextUI/CommandTest.php
84 84 * Tests the result of the print version option.
85 85 *
86 86 * @return void
87 + * @covers PHP_Depend_TextUI_Command
88 + * @group pdepend
89 + * @group pdepend::textui
90 + * @group unittest
87 91 */
88 92 public function testPrintVersion()
89 93 {
97 101 * Tests the result of the print usage option.
98 102 *
99 103 * @return void
104 + * @covers PHP_Depend_TextUI_Command
105 + * @group pdepend
106 + * @group pdepend::textui
107 + * @group unittest
100 108 */
101 109 public function testPrintUsage()
102 110 {
112 120 * Tests the output of the print help option.
113 121 *
114 122 * @return void
123 + * @covers PHP_Depend_TextUI_Command
124 + * @group pdepend
125 + * @group pdepend::textui
126 + * @group unittest
115 127 */
116 128 public function testPrintHelp()
117 129 {
126 138 * Tests that the command exits with an cli error if no $argv array exists.
127 139 *
128 140 * @return void
141 + * @covers PHP_Depend_TextUI_Command
142 + * @group pdepend
143 + * @group pdepend::textui
144 + * @group unittest
129 145 */
130 146 public function testCommandExitsWithCliErrorIfNotArgvArrayExists()
131 147 {
141 157 * Tests that the command exits with a cli error for an empty option list.
142 158 *
143 159 * @return void
160 + * @covers PHP_Depend_TextUI_Command
161 + * @group pdepend
162 + * @group pdepend::textui
163 + * @group unittest
144 164 */
145 165 public function testCommandExitsWithCliErrorForEmptyOptionList()
146 166 {
155 175 * Tests that the command starts the text ui runner.
156 176 *
157 177 * @return void
178 + * @covers PHP_Depend_TextUI_Command
179 + * @group pdepend
180 + * @group pdepend::textui
181 + * @group unittest
158 182 */
159 183 public function testCommandStartsProcessWithDummyLogger()
160 184 {
171 195 $source
172 196 );
173 197
174 - if (file_exists($logFile)) {
175 - unlink($logFile);
176 - }
177 -
178 198 list($exitCode, $actual) = $this->_executeCommand($argv);
179 199
180 200 $this->assertEquals(PHP_Depend_TextUI_Runner::SUCCESS_EXIT, $exitCode);
181 201 $this->assertFileExists($logFile);
182 -
183 - unlink($logFile);
184 202 }
185 203
186 204 /**
187 205 * Tests that the command exits with a cli error for an unknown option.
188 206 *
189 207 * @return void
208 + * @covers PHP_Depend_TextUI_Command
209 + * @group pdepend
210 + * @group pdepend::textui
211 + * @group unittest
190 212 */
191 213 public function testCommandExitsWithCliErrorForUnknownOption()
192 214 {
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 {
311 347 '-d',
312 348 'html_errors',
313 349 '--dummy-logger=' . self::createRunResourceURI('pdepend.dummy'),
314 - dirname(__FILE__)
350 + __FILE__
315 351 );
316 352
317 353 list($exitCode, $actual) = $this->_executeCommand($argv);
326 362 * Tests that the text ui command handles an ini option "-d key=value" correct.
327 363 *
328 364 * @return void
365 + * @covers PHP_Depend_TextUI_Command
366 + * @group pdepend
367 + * @group pdepend::textui
368 + * @group unittest
329 369 */
330 370 public function testCommandHandlesIniOptionWithValue()
331 371 {
338 378 '-d',
339 379 'html_errors=off',
340 380 '--dummy-logger=' . self::createRunResourceURI('pdepend.dummy'),
341 - dirname(__FILE__)
381 + __FILE__
342 382 );
343 383
344 384 list($exitCode, $actual) = $this->_executeCommand($argv);
354 394 * config file.
355 395 *
356 396 * @return void
397 + * @covers PHP_Depend_TextUI_Command
398 + * @group pdepend
399 + * @group pdepend::textui
400 + * @group unittest
357 401 */
358 402 public function testCommandHandlesConfigurationFileCorrect()
359 403 {
371 415 $argv = array(
372 416 '--configuration=' . $configFile,
373 417 '--dummy-logger=' . self::createRunResourceURI('pdepend.dummy'),
374 - dirname(__FILE__)
418 + __FILE__
375 419 );
376 420
377 421 // Result previous instance
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
434 529 $this->assertRegExp('( --ignore=<dir\[,\.{3}\]>[ ]+List\s+of\s+exclude\s+directories\.)', $actual);
435 530 $this->assertRegExp('( --exclude=<pkg\[,\.{3}\]>[ ]+List\s+of\s+exclude\s+packages\.)', $actual);
436 531 $this->assertRegExp('( --without-annotations[ ]+Do\s+not\s+parse\s+doc\s+comment\s+annotations\.)', $actual);
437 - $this->assertRegExp('( --bad-documentation[ ]+Fallback\s+for\s+projects\s+with\s+bad\s+doc\s+comments\.)', $actual);
438 532 $this->assertRegExp('( --optimization=<mode>[ ]+Runtime\s+switch\s+to\s+influence\s+the\s+internal\s+processing\.)', $actual);
439 533 $this->assertRegExp('( [ ]+"best"[ ]+Provides\s+lowest\s+memory\s+usage\s+with\s+best\s+possible\s+performance\.)', $actual);
440 534 $this->assertRegExp('( [ ]+"none"[ ]+Highest\s+memory\s+usage\s+without\s+any\s+caching\.)', $actual);
1030 1032 /tests/PHP/Depend/ParserRegressionTest.php
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 +}
1030 1032 /tests/PHP/Depend/DependTest.php
136 136 }
137 137
138 138 /**
139 - * Tests that {@PHP_Depend::analyze()} throws an exception if no custom
140 - * packages exist.
139 + * testAnalyzerReturnsEmptyIteratorWhenNoPackageExists
141 140 *
142 141 * @return void
142 + * @covers PHP_Depend
143 + * @group pdepend
144 + * @group unittest
143 145 */
144 - public function testAnalyzerThrowsAnExceptionIfTheParserDoesntDetectCustomPackages()
146 + public function testAnalyzerReturnsEmptyIteratorWhenNoPackageExists()
145 147 {
146 148 $pdepend = new PHP_Depend();
147 149 $pdepend->addDirectory(dirname(__FILE__) . '/_code/code-without-comments');
148 -
149 - $message = "The parser doesn't detect package informations within the "
150 - . "analyzed project, please check the documentation blocks for "
151 - . "@package-annotations or use the --bad-documentation option.";
152 -
153 - $this->setExpectedException('RuntimeException', $message);
154 -
155 - $pdepend->analyze();
150 + $pdepend->addFileFilter(new PHP_Depend_Input_ExtensionFilter(array(__METHOD__)));
151 +
152 + $this->assertEquals(0, $pdepend->analyze()->count());
156 153 }
157 154
158 155 /**
225 222 $pdepend->addDirectory(dirname(__FILE__) . '/_code/code-5.2.x');
226 223 $pdepend->analyze();
227 224
228 - $this->assertEquals(3, $pdepend->countPackages());
225 + $this->assertEquals(4, $pdepend->countPackages());
229 226 }
230 227
231 228 /**
346 343 $pdepend->addDirectory(dirname(__FILE__) . '/_code/code-5.2.x');
347 344 $pdepend->getPackages();
348 345 }
349 -
350 - /**
351 - * Tests the <b>--bad-documentation</b> option support.
352 - *
353 - * @return void
354 - */
355 - public function testSupportBadDocumentation()
356 - {
357 - $pdepend = new PHP_Depend();
358 - $pdepend->addDirectory(dirname(__FILE__) . '/_code/code-without-comments');
359 - $pdepend->setSupportBadDocumentation();
360 - $pdepend->analyze();
361 - $this->assertEquals(1, $pdepend->getPackages()->count());
362 - }
363 346
364 347 /**
365 348 * Tests the newly added support for single file handling.
402 385 }
403 386
404 387 /**
388 + * testSetStorageSetsPruneFlagOnTokenCache
389 + *
390 + * @return void
391 + * @covers PHP_Depend
392 + * @group pdepend
393 + * @group unittest
394 + */
395 + public function testSetStorageSetsPruneFlagOnTokenCache()
396 + {
397 + $cache = $this->getMock('PHP_Depend_Storage_EngineI');
398 + $cache->expects($this->once())
399 + ->method('setPrune');
400 +
401 + $pdepend = new PHP_Depend();
402 + $pdepend->setStorage(PHP_Depend::TOKEN_STORAGE, $cache);
403 + }
404 +
405 + /**
406 + * testSetStorageSetsMaxLifetimeAndProbabilityOnParserCache
407 + *
408 + * @return void
409 + * @covers PHP_Depend
410 + * @group pdepend
411 + * @group unittest
412 + */
413 + public function testSetStorageSetsMaxLifetimeAndProbabilityOnParserCache()
414 + {
415 + $cache = $this->getMock('PHP_Depend_Storage_EngineI');
416 + $cache->expects($this->once())
417 + ->method('setProbability');
418 + $cache->expects($this->once())
419 + ->method('setMaxLifetime');
420 +
421 + $pdepend = new PHP_Depend();
422 + $pdepend->setStorage(PHP_Depend::PARSER_STORAGE, $cache);
423 + }
424 +
425 + /**
405 426 * Tests that the setStorage() method throws an exception when an invalid
406 427 * storage type was given.
407 428 *
1030 1032 /tests/PHP/Depend/Builder/DefaultTest.php
42 42 * @author Manuel Pichler <mapi@pdepend.org>
43 43 * @copyright 2008-2010 Manuel Pichler. All rights reserved.
44 44 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
45 - * @version SVN: $Id: DefaultTest.php 675 2009-03-05 07:40:28Z mapi $
45 + * @version SVN: $Id$
46 46 * @link http://pdepend.org/
47 47 */
48 48
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 {
85 157 * different packages.
86 158 *
87 159 * @return void
160 + * @covers PHP_Depend_Builder_Default
161 + * @group pdepend
162 + * @group pdepend::builder
163 + * @group unittest
88 164 */
89 165 public function testBuildClassCreatesTwoDifferentInstancesForDifferentPackages()
90 166 {
101 177 * same named class in the default package.
102 178 *
103 179 * @return void
180 + * @covers PHP_Depend_Builder_Default
181 + * @group pdepend
182 + * @group pdepend::builder
183 + * @group unittest
104 184 */
105 185 public function testBuildClassReusesExistingNonDefaultPackageInstanceForDefaultPackage()
106 186 {
123 203 * same identifier.
124 204 *
125 205 * @return void
206 + * @covers PHP_Depend_Builder_Default
207 + * @group pdepend
208 + * @group pdepend::builder
209 + * @group unittest
126 210 */
127 211 public function testBuildInterfaceUnique()
128 212 {
141 225 * types with the same local or package internal name.
142 226 *
143 227 * @return void
228 + * @covers PHP_Depend_Builder_Default
229 + * @group pdepend
230 + * @group pdepend::builder
231 + * @group unittest
144 232 */
145 233 public function testBuildInterfaceDoesntRemoveClassForSameNamedInterface()
146 234 {
164 252 * different interface instances for different parent packages.
165 253 *
166 254 * @return void
255 + * @covers PHP_Depend_Builder_Default
256 + * @group pdepend
257 + * @group pdepend::builder
258 + * @group unittest
167 259 */
168 260 public function testBuildInterfacesCreatesDifferentInstancesForDifferentPackages()
169 261 {
181 273 * more specific version.
182 274 *
183 275 * @return void
276 + * @covers PHP_Depend_Builder_Default
277 + * @group pdepend
278 + * @group pdepend::builder
279 + * @group unittest
184 280 */
185 281 public function testCanCreateMultipleInterfaceInstancesWithIdenticalNames()
186 282 {
202 298 * for a same named interface in the default package.
203 299 *
204 300 * @return void
301 + * @covers PHP_Depend_Builder_Default
302 + * @group pdepend
303 + * @group pdepend::builder
304 + * @group unittest
205 305 */
206 306 public function testBuildInterfaceReusesExistingNonDefaultPackageInstanceForDefaultPackage()
207 307 {
220 320 * Tests the PHP_Depend_Code_Method build method.
221 321 *
222 322 * @return void
323 + * @covers PHP_Depend_Builder_Default
324 + * @group pdepend
325 + * @group pdepend::builder
326 + * @group unittest
223 327 */
224 328 public function testBuildMethod()
225 329 {
233 337 * Tests that the node builder creates a package for the same name only once.
234 338 *
235 339 * @return void
340 + * @covers PHP_Depend_Builder_Default
341 + * @group pdepend
342 + * @group pdepend::builder
343 + * @group unittest
236 344 */
237 345 public function testBuildPackageUnique()
238 346 {
250 358 * Tests the implemented {@link IteratorAggregate}.
251 359 *
252 360 * @return void
361 + * @covers PHP_Depend_Builder_Default
362 + * @group pdepend
363 + * @group pdepend::builder
364 + * @group unittest
253 365 */
254 366 public function testGetIteratorWithPackages()
255 367 {
272 384 * Tests the {@link PHP_Depend_Builder_Default::getPackages()} method.
273 385 *
274 386 * @return void
387 + * @covers PHP_Depend_Builder_Default
388 + * @group pdepend
389 + * @group pdepend::builder
390 + * @group unittest
275 391 */
276 392 public function testGetPackages()
277 393 {
295 411 * has alway overwritten previously created instances.
296 412 *
297 413 * @return void
414 + * @covers PHP_Depend_Builder_Default
415 + * @group pdepend
416 + * @group pdepend::builder
417 + * @group unittest
298 418 */
299 419 public function testBuildClassDoesNotOverwritePreviousInstances()
300 420 {
315 435 * has alway overwritten previously created instances.
316 436 *
317 437 * @return void
438 + * @covers PHP_Depend_Builder_Default
439 + * @group pdepend
440 + * @group pdepend::builder
441 + * @group unittest
318 442 */
319 443 public function testBuildInterfaceDoesNotOverwritePreviousInstances()
320 444 {
331 455 * Tests that the node builder works case insensitive for class names.
332 456 *
333 457 * @return void
458 + * @covers PHP_Depend_Builder_Default
459 + * @group pdepend
460 + * @group pdepend::builder
461 + * @group unittest
334 462 */
335 463 public function testBuildClassWorksCaseInsensitiveIssue26()
336 464 {
346 474 * Tests that the node builder works case insensitive for interface names.
347 475 *
348 476 * @return void
477 + * @covers PHP_Depend_Builder_Default
478 + * @group pdepend
479 + * @group pdepend::builder
480 + * @group unittest
349 481 */
350 482 public function testBuildInterfaceWorksCaseInsensitiveIssue26()
351 483 {
361 493 * Tests that the node builder works case insensitive for interface names.
362 494 *
363 495 * @return void
496 + * @covers PHP_Depend_Builder_Default
497 + * @group pdepend
498 + * @group pdepend::builder
499 + * @group unittest
364 500 */
365 501 public function testBuildClassOrInterfaceWorksCaseInsensitive1Issue26()
366 502 {
376 512 * Tests that the node builder works case insensitive for interface names.
377 513 *
378 514 * @return void
515 + * @covers PHP_Depend_Builder_Default
516 + * @group pdepend
517 + * @group pdepend::builder
518 + * @group unittest
379 519 */
380 520 public function testBuildClassOrInterfaceWorksCaseInsensitive2Issue26()
381 521 {
392 532 * to build a new node, when the internal state flag is frozen.
393 533 *
394 534 * @return void
535 + * @covers PHP_Depend_Builder_Default
536 + * @group pdepend
537 + * @group pdepend::builder
538 + * @group unittest
395 539 */
396 540 public function testBuildASTClassOrInterfaceReferenceThrowsExpectedExceptionWhenStateIsFrozen()
397 541 {
414 558 * to build a new node, when the internal state flag is frozen.
415 559 *
416 560 * @return void
561 + * @covers PHP_Depend_Builder_Default
562 + * @group pdepend
563 + * @group pdepend::builder
564 + * @group unittest
417 565 */
418 566 public function testBuildClassThrowsExpectedExceptionWhenStateIsFrozen()
419 567 {
436 584 * to build a new node, when the internal state flag is frozen.
437 585 *
438 586 * @return void
587 + * @covers PHP_Depend_Builder_Default
588 + * @group pdepend
589 + * @group pdepend::builder
590 + * @group unittest
439 591 */
440 592 public function testBuildASTClassReferenceThrowsExpectedExceptionWhenStateIsFrozen()
441 593 {
458 610 * to build a new node, when the internal state flag is frozen.
459 611 *
460 612 * @return void
613 + * @covers PHP_Depend_Builder_Default
614 + * @group pdepend
615 + * @group pdepend::builder
616 + * @group unittest
461 617 */
462 618 public function testBuildClosureThrowsExpectedExceptionWhenStateIsFrozen()
463 619 {
480 636 * to build a new node, when the internal state flag is frozen.
481 637 *
482 638 * @return void
639 + * @covers PHP_Depend_Builder_Default
640 + * @group pdepend
641 + * @group pdepend::builder
642 + * @group unittest
483 643 */
484 644 public function testBuildInterfaceThrowsExpectedExceptionWhenStateIsFrozen()
485 645 {
502 662 * to build a new node, when the internal state flag is frozen.
503 663 *
504 664 * @return void
665 + * @covers PHP_Depend_Builder_Default
666 + * @group pdepend
667 + * @group pdepend::builder
668 + * @group unittest
505 669 */
506 670 public function testBuildInterfaceReferenceThrowsExpectedExceptionWhenStateIsFrozen()
507 671 {
524 688 * to build a new node, when the internal state flag is frozen.
525 689 *
526 690 * @return void
691 + * @covers PHP_Depend_Builder_Default
692 + * @group pdepend
693 + * @group pdepend::builder
694 + * @group unittest
527 695 */
528 696 public function testBuildMethodThrowsExpectedExceptionWhenStateIsFrozen()
529 697 {
546 714 * to build a new node, when the internal state flag is frozen.
547 715 *
548 716 * @return void
717 + * @covers PHP_Depend_Builder_Default
718 + * @group pdepend
719 + * @group pdepend::builder
720 + * @group unittest
549 721 */
550 722 public function testBuildFunctionThrowsExpectedExceptionWhenStateIsFrozen()
551 723 {
1030 1032 /tests/PHP/Depend/AbstractTest.php
70 70 {
71 71 parent::setUp();
72 72
73 - $files = new RecursiveIteratorIterator(
74 - new RecursiveDirectoryIterator(dirname(__FILE__) . '/_run')
75 - );
73 + $run = dirname(__FILE__) . '/_run';
74 + if (file_exists($run) === false) {
75 + mkdir($run, 0755);
76 + }
76 77
77 - foreach ($files as $file) {
78 - $pathName = realpath($file->getPathname());
79 - $fileName = $file->getFilename();
80 - if ($fileName === '.'
81 - || $fileName === '..'
82 - || strpos($pathName, '.svn') !== false) {
83 - continue;
84 - }
78 + $this->_clearRunResources($run);
85 79
86 - if ($file->isDir() === true) {
87 - rmdir($pathName);
88 - } else {
89 - unlink($pathName);
90 - }
91 - }
92 -
93 80 include_once 'PHP/Depend.php';
94 81 include_once 'PHP/Depend/StorageRegistry.php';
95 82 include_once 'PHP/Depend/Storage/MemoryEngine.php';
115 102 */
116 103 protected function tearDown()
117 104 {
118 - PHP_Depend_Code_Filter_Collection::getInstance()->clear();
105 + PHP_Depend_Code_Filter_Collection::getInstance()->setFilter();
119 106
107 + $this->_clearRunResources();
108 +
120 109 parent::tearDown();
121 110 }
122 111
123 112 /**
113 + * Clears all temporary resources.
114 + *
115 + * @param string $dir The root directory.
116 + *
117 + * @return void
118 + */
119 + private function _clearRunResources($dir = null)
120 + {
121 + if ($dir === null) {
122 + $dir = dirname(__FILE__) . '/_run';
123 + }
124 +
125 + foreach (new DirectoryIterator($dir) as $file) {
126 + if ($file == '.' || $file == '..' || $file == '.svn') {
127 + continue;
128 + }
129 + $pathName = realpath($file->getPathname());
130 + if ($file->isDir()) {
131 + $this->_clearRunResources($pathName);
132 + rmdir($pathName);
133 + } else {
134 + unlink($pathName);
135 + }
136 + }
137 + }
138 +
139 + /**
124 140 * Creates a temporary resource for the given file name.
125 141 *
126 142 * @param string $fileName The temporary file name.
1030 1032 /tests/PHP/Depend/Parser/AllTests.php
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 +}
1030 1032 /tests/PHP/Depend/Parser/FunctionNameParserImplTest.php
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 +}
1030 1032 /tests/PHP/Depend/Visitor/DefaultListenerTest.php
51 51 require_once dirname(__FILE__) . '/DefaultVisitorDummy.php';
52 52 require_once dirname(__FILE__) . '/TestListener.php';
53 53
54 +require_once 'PHP/Depend/Code/Parameter.php';
55 +
54 56 /**
55 57 * Test case for the default visit listener implementation.
56 58 *
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 /**
103 121 * to the startVisitNode() and endVisitNode() methods.
104 122 *
105 123 * @return void
124 + * @covers PHP_Depend_Visitor_AbstractListener
125 + * @group pdepend
126 + * @group pdepend::visitor
127 + * @group unittest
106 128 */
107 129 public function testListenerCallsStartNodeEndNodeForClass()
108 130 {
132 154
133 155 $class->accept($visitor);
134 156
135 - $this->assertArrayHasKey(__FUNCTION__ . '#start', $listener->nodes);
136 - $this->assertArrayHasKey(__FUNCTION__ . '#end', $listener->nodes);
157 + $actual = $listener->nodes;
158 + $expected = array(
159 + __FUNCTION__ . '#start' => true,
160 + __FUNCTION__ . '#end' => true,
161 + );
162 +
163 + $this->assertEquals($expected, $actual);
137 164 }
138 165
139 166 /**
141 168 * call to the startVisitNode() and endVisitNode() methods.
142 169 *
143 170 * @return void
171 + * @covers PHP_Depend_Visitor_AbstractListener
172 + * @group pdepend
173 + * @group pdepend::visitor
174 + * @group unittest
144 175 */
145 176 public function testListenerCallsStartNodeEndNodeForInterface()
146 177 {
170 201
171 202 $interface->accept($visitor);
172 203
173 - $this->assertArrayHasKey(__FUNCTION__ . '#start', $listener->nodes);
174 - $this->assertArrayHasKey(__FUNCTION__ . '#end', $listener->nodes);
204 + $actual = $listener->nodes;
205 + $expected = array(
206 + __FUNCTION__ . '#start' => true,
207 + __FUNCTION__ . '#end' => true,
208 + );
209 +
210 + $this->assertEquals($expected, $actual);
175 211 }
176 212
177 213 /**
179 215 * call to the startVisitNode() and endVisitNode() methods.
180 216 *
181 217 * @return void
218 + * @covers PHP_Depend_Visitor_AbstractListener
219 + * @group pdepend
220 + * @group pdepend::visitor
221 + * @group unittest
182 222 */
183 223 public function testListenerCallsStartNodeEndNodeForFunction()
184 224 {
211 251
212 252 $function->accept($visitor);
213 253
214 - $this->assertArrayHasKey(__FUNCTION__ . '#start', $listener->nodes);
215 - $this->assertArrayHasKey(__FUNCTION__ . '#end', $listener->nodes);
254 + $actual = $listener->nodes;
255 + $expected = array(
256 + __FUNCTION__ . '#start' => true,
257 + __FUNCTION__ . '#end' => true,
258 + );
259 +
260 + $this->assertEquals($expected, $actual);
216 261 }
217 262
218 263 /**
220 265 * the startVisitNode() and endVisitNode() methods.
221 266 *
222 267 * @return void
268 + * @covers PHP_Depend_Visitor_AbstractListener
269 + * @group pdepend
270 + * @group pdepend::visitor
271 + * @group unittest
223 272 */
224 273 public function testListenerCallsStartNodeEndNodeForMethod()
225 274 {
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 +}
1030 1032 /tests/PHP/Depend/Visitor/DefaultVisitorDummy.php
96 96 */
97 97 public function visitFile(PHP_Depend_Code_File $file)
98 98 {
99 - $this->visits[] = $file->getName();
99 + $this->visits[] = get_class($file);
100 100
101 101 parent::visitFile($file);
102 102 }
1030 1032 /tests/PHP/Depend/Visitor/DefaultVisitorTest.php
58 58 require_once 'PHP/Depend/Code/NodeIterator.php';
59 59 require_once 'PHP/Depend/Code/Package.php';
60 60 require_once 'PHP/Depend/Code/Property.php';
61 +require_once 'PHP/Depend/Visitor/ListenerI.php';
61 62
62 63 /**
63 64 * Test case for the default visitor implementation.
80 81 */
81 82 public function testDefaultVisitOrder()
82 83 {
83 - $codeUri = self::createCodeResourceURI('visitor/' . __FUNCTION__ . '.php');
84 - $packages = self::parseSource($codeUri);
84 + $packages = self::parseTestCaseSource(__METHOD__);
85 85
86 86 $visitor = new PHP_Depend_Visitor_DefaultVisitorDummy();
87 87 foreach ($packages as $package) {
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 }
1030 1032 /tests/PHP/Depend/Visitor/TestListener.php
65 65
66 66 public function startVisitNode(PHP_Depend_Code_NodeI $node)
67 67 {
68 - $this->nodes[$node->getName() . '#start'] = $node;
68 + $this->nodes[$node->getName() . '#start'] = true;
69 69
70 70 parent::startVisitNode($node);
71 71 }
72 72
73 73 public function endVisitNode(PHP_Depend_Code_NodeI $node)
74 74 {
75 - $this->nodes[$node->getName() . '#end'] = $node;
75 + $this->nodes[$node->getName() . '#end'] = true;
76 76
77 77 parent::endVisitNode($node);
78 78 }
1030 1032 /tests/PHP/Depend/Visitor/TestNodeVisitor.php
111 111 public $function = null;
112 112
113 113 /**
114 - * The last visited type constant instance.
115 - *
116 - * @var PHP_Depend_Code_TypeConstant $typeConstant
117 - */
118 - public $typeConstant = null;
119 -
120 - /**
121 114 * Adds a new listener to this node visitor.
122 115 *
123 116 * @param PHP_Depend_Visitor_ListenerI $listener
142 135 }
143 136
144 137 /**
145 - * Visits a closure node.
146 - *
147 - * @param PHP_Depend_Code_Closure $closure The current closure node.
148 - *
149 - * @return void
150 - */
151 - public function visitClosure(PHP_Depend_Code_Closure $closure)
152 - {
153 -
154 - }
155 -
156 - /**
157 138 * Visits a code interface object.
158 139 *
159 140 * @param PHP_Depend_Code_Interface $interface The context code interface.
238 219 {
239 220
240 221 }
241 -
242 - /**
243 - * Visits a class constant node.
244 - *
245 - * @param PHP_Depend_Code_TypeConstant $constant The current constant node.
246 - *
247 - * @return void
248 - */
249 - public function visitTypeConstant(PHP_Depend_Code_TypeConstant $constant)
250 - {
251 - $this->typeConstant = $constant;
252 - }
253 -}
222 +}
1030 1032 /tests/PHP/Depend/Input/IteratorTest.php
70 70 * Tests that the filter iterator only returns files with a .php extension.
71 71 *
72 72 * @return void
73 + * @covers PHP_Depend_Input_Iterator
74 + * @group pdepend
75 + * @group pdepend::input
76 + * @group unittest
73 77 */
74 - public function testFilterIterator()
78 + public function testIteratorWithExtensionFilterForPhpFilesOnly()
75 79 {
76 - $dir = dirname(__FILE__) . '/../_code';
80 + $dir = self::createCodeResourceURI('input/iterator');
77 81 $it = new PHP_Depend_Input_Iterator(
78 82 new DirectoryIterator($dir),
79 83 new PHP_Depend_Input_ExtensionFilter(array('php'))
80 84 );
81 85
82 86 $expected = array(
83 - 'class_and_interface_comment.php',
84 - 'classes.php',
85 - 'func_class.php',
86 - 'func_code.php',
87 - 'mixed_code.php',
88 - 'package_file_level.php',
89 - 'package_subpackage_support.php',
87 + 'class.php',
88 + 'mixed.php',
89 + 'package.php',
90 90 );
91 91
92 92 $result = array();
99 99
100 100 $this->assertEquals($expected, $result);
101 101 }
102 +
103 + /**
104 + * testIteratorWithExtensionFilterForIncAndTxtFiles
105 + *
106 + * @return void
107 + * @covers PHP_Depend_Input_Iterator
108 + * @group pdepend
109 + * @group pdepend::input
110 + * @group unittest
111 + */
112 + public function testIteratorWithExtensionFilterForIncAndTxtFiles()
113 + {
114 + $dir = self::createCodeResourceURI('input/iterator');
115 + $it = new PHP_Depend_Input_Iterator(
116 + new DirectoryIterator($dir),
117 + new PHP_Depend_Input_ExtensionFilter(array('inc', 'txt'))
118 + );
119 +
120 + $expected = array(
121 + 'function.inc',
122 + 'function.txt',
123 + );
124 +
125 + $result = array();
126 + foreach ($it as $file) {
127 + $result[] = $file->getFilename();
128 + }
129 +
130 + sort($expected);
131 + sort($result);
132 +
133 + $this->assertEquals($expected, $result);
134 + }
102 135 }
1030 1032 /tests/PHP/Depend/Bugs/EndLessLoopBetweenForParentClassBug152Test.php
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 +}
1030 1032 /tests/PHP/Depend/Bugs/ComplexStringParsingBug114Test.php
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