Arbit - project tracking

PHP Depend

Browse source code

File: / tests/ PHP/ Depend/ Issues/ NamespaceSupportIssue002Test.php

Type
text/plain text/plain
Last Author
mapi
Version
1307
Line Rev. Author Source
1 735 mapi <?php
2 mapi /**
3 mapi * This file is part of PHP_Depend.
4 mapi *
5 mapi * PHP Version 5
6 mapi *
7 1030 mapi * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>.
8 735 mapi * All rights reserved.
9 mapi *
10 mapi * Redistribution and use in source and binary forms, with or without
11 mapi * modification, are permitted provided that the following conditions
12 mapi * are met:
13 mapi *
14 mapi * * Redistributions of source code must retain the above copyright
15 mapi * notice, this list of conditions and the following disclaimer.
16 mapi *
17 mapi * * Redistributions in binary form must reproduce the above copyright
18 mapi * notice, this list of conditions and the following disclaimer in
19 mapi * the documentation and/or other materials provided with the
20 mapi * distribution.
21 mapi *
22 mapi * * Neither the name of Manuel Pichler nor the names of his
23 mapi * contributors may be used to endorse or promote products derived
24 mapi * from this software without specific prior written permission.
25 mapi *
26 mapi * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 mapi * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 mapi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 mapi * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 mapi * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 mapi * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 mapi * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 mapi * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 mapi * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 mapi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 mapi * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 mapi * POSSIBILITY OF SUCH DAMAGE.
38 mapi *
39 mapi * @category PHP
40 mapi * @package PHP_Depend
41 mapi * @subpackage Issues
42 mapi * @author Manuel Pichler <mapi@pdepend.org>
43 1030 mapi * @copyright 2008-2010 Manuel Pichler. All rights reserved.
44 735 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
45 mapi * @version SVN: $Id$
46 mapi * @link http://www.pdepend.org/
47 mapi */
48 mapi
49 mapi require_once dirname(__FILE__) . '/../AbstractTest.php';
50 mapi
51 mapi /**
52 mapi * Test case for ticket 002, PHP 5.3 namespace support.
53 mapi *
54 mapi * @category PHP
55 mapi * @package PHP_Depend
56 mapi * @subpackage Issues
57 mapi * @author Manuel Pichler <mapi@pdepend.org>
58 1030 mapi * @copyright 2008-2010 Manuel Pichler. All rights reserved.
59 735 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
60 mapi * @version Release: @package_version@
61 mapi * @link http://www.pdepend.org/
62 mapi */
63 739 mapi class PHP_Depend_Issues_NamespaceSupportIssue002Test extends PHP_Depend_AbstractTest
64 735 mapi {
65 mapi /**
66 mapi * Tests that the parser handles a simple use statement as expected.
67 mapi *
68 mapi * @return void
69 1041 mapi * @covers PHP_Depend_Parser
70 mapi * @group pdepend
71 mapi * @group pdepend::issues
72 mapi * @group pdepend::parser
73 mapi * @group unittest
74 735 mapi */
75 mapi public function testParserHandlesSimpleUseDeclaration()
76 mapi {
77 mapi $packages = self::parseSource('issues/002-001-use-declaration.php');
78 mapi
79 mapi $class = $packages->current()
80 mapi ->getClasses()
81 mapi ->current();
82 mapi
83 mapi $parentClass = $class->getParentClass();
84 mapi $this->assertSame('Bar', $parentClass->getName());
85 mapi $this->assertSame('foo', $parentClass->getPackage()->getName());
86 mapi }
87 mapi
88 mapi /**
89 mapi * Tests that the parser handles multiple, comma separated use declarations.
90 mapi *
91 mapi * @return void
92 1041 mapi * @covers PHP_Depend_Parser
93 mapi * @group pdepend
94 mapi * @group pdepend::issues
95 mapi * @group pdepend::parser
96 mapi * @group unittest
97 735 mapi */
98 mapi public function testParserHandlesMultipleUseDeclarations()
99 mapi {
100 mapi $packages = self::parseSource('issues/002-002-use-declaration.php');
101 mapi
102 mapi $class = $packages->current()
103 mapi ->getClasses()
104 mapi ->current();
105 mapi
106 mapi $parentClass = $class->getParentClass();
107 mapi $this->assertSame('FooBar', $parentClass->getName());
108 mapi $this->assertSame('foo', $parentClass->getPackage()->getName());
109 mapi
110 mapi $interface = $class->getInterfaces()->current();
111 mapi $this->assertSame('Bar', $interface->getName());
112 mapi $this->assertSame('foo', $interface->getPackage()->getName());
113 mapi }
114 736 mapi
115 737 mapi /**
116 mapi * Tests that parser handles a use declaration case insensitive.
117 mapi *
118 mapi * @return void
119 1041 mapi * @covers PHP_Depend_Parser
120 mapi * @group pdepend
121 mapi * @group pdepend::issues
122 mapi * @group pdepend::parser
123 mapi * @group unittest
124 737 mapi */
125 736 mapi public function testParserHandlesUseDeclarationCaseInsensitive()
126 mapi {
127 mapi $packages = self::parseSource('issues/002-003-use-declaration.php');
128 mapi
129 mapi $class = $packages->current()
130 mapi ->getClasses()
131 mapi ->current();
132 mapi
133 mapi $parentClass = $class->getParentClass();
134 mapi $this->assertSame('Bar', $parentClass->getName());
135 786 mapi $this->assertSame('foo\bar', $parentClass->getPackage()->getName());
136 736 mapi }
137 737 mapi
138 mapi /**
139 mapi * Tests that parser throws an expected exception.
140 mapi *
141 mapi * @return void
142 1041 mapi * @covers PHP_Depend_Parser
143 mapi * @group pdepend
144 mapi * @group pdepend::issues
145 mapi * @group pdepend::parser
146 mapi * @group unittest
147 737 mapi */
148 mapi public function testParserThrowsExpectedExceptionWhenUseDeclarationContextEndsOnBackslash()
149 mapi {
150 mapi $this->setExpectedException(
151 mapi 'PHP_Depend_Parser_UnexpectedTokenException',
152 mapi 'Unexpected token: as, line: 2, col: 19, file: '
153 mapi );
154 mapi
155 mapi self::parseSource('issues/002-004-use-declaration.php');
156 mapi }
157 747 mapi
158 mapi /**
159 mapi * Tests that the parser handles a namespace declaration with namespace
160 mapi * identifier and curly brace syntax.
161 mapi *
162 mapi * @return void
163 1041 mapi * @covers PHP_Depend_Parser
164 mapi * @group pdepend
165 mapi * @group pdepend::issues
166 mapi * @group pdepend::parser
167 mapi * @group unittest
168 747 mapi */
169 mapi public function testParserHandlesNamespaceDeclarationWithIdentifierAndCurlyBraceSyntax()
170 mapi {
171 mapi $packages = self::parseSource('issues/002-005-namespace-declaration.php');
172 mapi
173 mapi $this->assertSame('foo', $packages->current()->getName());
174 mapi }
175 mapi
176 mapi /**
177 mapi * Tests that the parser handles a namespace declaration with namespace
178 mapi * identifier and semicolon syntax.
179 mapi *
180 mapi * @return void
181 1041 mapi * @covers PHP_Depend_Parser
182 mapi * @group pdepend
183 mapi * @group pdepend::issues
184 mapi * @group pdepend::parser
185 mapi * @group unittest
186 747 mapi */
187 mapi public function testParserHandlesNamespaceDeclarationWithIdentifierAndSemicolonSyntax()
188 mapi {
189 mapi $packages = self::parseSource('issues/002-006-namespace-declaration.php');
190 mapi
191 mapi $this->assertSame('foo', $packages->current()->getName());
192 mapi }
193 mapi
194 mapi /**
195 mapi * Tests that the parser handles a namespace declaration without namespace
196 mapi * identifier and semicolon syntax.
197 mapi *
198 mapi * @return void
199 1041 mapi * @covers PHP_Depend_Parser
200 mapi * @group pdepend
201 mapi * @group pdepend::issues
202 mapi * @group pdepend::parser
203 mapi * @group unittest
204 747 mapi */
205 mapi public function testParserHandlesNamespaceDeclarationWithoutIdentifierAndCurlyBraceSyntax()
206 mapi {
207 mapi $packages = self::parseSource('issues/002-007-namespace-declaration.php');
208 mapi
209 mapi $this->assertSame('', $packages->current()->getName());
210 mapi }
211 mapi
212 mapi /**
213 mapi * Tests that the parser does not accept an empty namespace identifier for
214 mapi * the semicolon syntax.
215 mapi *
216 mapi * @return void
217 1041 mapi * @covers PHP_Depend_Parser
218 mapi * @group pdepend
219 mapi * @group pdepend::issues
220 mapi * @group pdepend::parser
221 mapi * @group unittest
222 747 mapi */
223 mapi public function testParserThrowsExpectedExceptionForNamespaceDeclarationWithoutIdentifierAndSemicolonSyntax()
224 mapi {
225 mapi $this->setExpectedException(
226 mapi 'PHP_Depend_Parser_UnexpectedTokenException',
227 mapi 'Unexpected token: ;, line: 2, col: 18, file: '
228 mapi
229 mapi );
230 mapi
231 mapi self::parseSource('issues/002-008-namespace-declaration.php');
232 mapi }
233 mapi
234 mapi /**
235 mapi * Tests that the parser does not accept a leading backslash in a namespace
236 mapi * identifier.
237 mapi *
238 mapi * @return void
239 1041 mapi * @covers PHP_Depend_Parser
240 mapi * @group pdepend
241 mapi * @group pdepend::issues
242 mapi * @group pdepend::parser
243 mapi * @group unittest
244 747 mapi */
245 mapi public function testParserThrowsExpectedExceptionForLeadingBackslashInIdentifier()
246 mapi {
247 mapi $this->setExpectedException(
248 mapi 'PHP_Depend_Parser_UnexpectedTokenException',
249 781 mapi 'Unexpected token: {, line: 2, col: 13, file: '
250 747 mapi
251 mapi );
252 mapi
253 mapi self::parseSource('issues/002-009-namespace-declaration.php');
254 mapi }
255 769 mapi
256 mapi /**
257 mapi * Tests that an existing namespace declaration has a higher priority than
258 mapi * a simply package annotation.
259 mapi *
260 mapi * @return void
261 1041 mapi * @covers PHP_Depend_Parser
262 mapi * @group pdepend
263 mapi * @group pdepend::issues
264 mapi * @group pdepend::parser
265 mapi * @group unittest
266 769 mapi */
267 771 mapi public function testNamespaceHasHigherPriorityThanPackageAnnotationSemicolonSyntax()
268 769 mapi {
269 mapi $packages = self::parseSource('issues/002-010-namespace-has-higher-priority.php');
270 mapi
271 mapi $class = $packages->current()
272 mapi ->getClasses()
273 mapi ->current();
274 mapi
275 mapi $this->assertSame('bar', $class->getPackage()->getName());
276 mapi }
277 771 mapi
278 mapi /**
279 mapi * Tests that an existing namespace declaration has a higher priority than
280 mapi * a simply package annotation.
281 mapi *
282 mapi * @return void
283 1041 mapi * @covers PHP_Depend_Parser
284 mapi * @group pdepend
285 mapi * @group pdepend::issues
286 mapi * @group pdepend::parser
287 mapi * @group unittest
288 771 mapi */
289 mapi public function testNamespaceHasHigherPriorityThanPackageAnnotationCurlyBraceSyntax()
290 mapi {
291 mapi $packages = self::parseSource('issues/002-011-namespace-has-higher-priority.php');
292 mapi
293 mapi $class = $packages->current()
294 mapi ->getClasses()
295 mapi ->current();
296 mapi
297 mapi $this->assertSame('bar', $class->getPackage()->getName());
298 mapi }
299 mapi
300 mapi /**
301 mapi * Tests that the parser handles multiple namespaces in a single file correct.
302 mapi *
303 mapi * @return void
304 1041 mapi * @covers PHP_Depend_Parser
305 mapi * @group pdepend
306 mapi * @group pdepend::issues
307 mapi * @group pdepend::parser
308 mapi * @group unittest
309 771 mapi */
310 mapi public function testParserHandlesFileWithMultipleNamespacesCorrectSemicolonSyntax()
311 mapi {
312 mapi $packages = self::parseSource('issues/002-012-multiple-namespaces.php');
313 mapi
314 mapi $this->assertSame(3, $packages->count());
315 mapi
316 mapi $package = $packages->current();
317 mapi $types = $package->getTypes();
318 mapi $this->assertSame('bar', $package->getName());
319 mapi $this->assertSame(1, $types->count());
320 mapi $this->assertSame('BarFoo', $types->current()->getName());
321 mapi
322 mapi $packages->next();
323 mapi
324 mapi $package = $packages->current();
325 mapi $types = $package->getTypes();
326 1027 mapi $this->assertSame('foo', $package->getName());
327 771 mapi $this->assertSame(1, $types->count());
328 1027 mapi $this->assertSame('FooBar', $types->current()->getName());
329 771 mapi
330 mapi $packages->next();
331 mapi
332 mapi $package = $packages->current();
333 mapi $types = $package->getTypes();
334 1027 mapi $this->assertSame('baz', $package->getName());
335 771 mapi $this->assertSame(1, $types->count());
336 1027 mapi $this->assertSame('FooBaz', $types->current()->getName());
337 771 mapi }
338 mapi
339 mapi /**
340 mapi * Tests that the parser handles multiple namespaces in a single file correct.
341 mapi *
342 mapi * @return void
343 1041 mapi * @covers PHP_Depend_Parser
344 mapi * @group pdepend
345 mapi * @group pdepend::issues
346 mapi * @group pdepend::parser
347 mapi * @group unittest
348 771 mapi */
349 mapi public function testParserHandlesFileWithMultipleNamespacesCorrectCurlyBraceSyntax()
350 mapi {
351 mapi $packages = self::parseSource('issues/002-013-multiple-namespaces.php');
352 mapi
353 mapi $this->assertSame(3, $packages->count());
354 mapi
355 mapi $package = $packages->current();
356 mapi $types = $package->getTypes();
357 mapi $this->assertSame('bar', $package->getName());
358 mapi $this->assertSame(1, $types->count());
359 mapi $this->assertSame('BarFoo', $types->current()->getName());
360 mapi
361 mapi $packages->next();
362 mapi
363 mapi $package = $packages->current();
364 mapi $types = $package->getTypes();
365 1027 mapi $this->assertSame('foo', $package->getName());
366 771 mapi $this->assertSame(1, $types->count());
367 1027 mapi $this->assertSame('FooBar', $types->current()->getName());
368 771 mapi
369 mapi $packages->next();
370 mapi
371 mapi $package = $packages->current();
372 mapi $types = $package->getTypes();
373 1027 mapi $this->assertSame('baz', $package->getName());
374 771 mapi $this->assertSame(1, $types->count());
375 1027 mapi $this->assertSame('FooBaz', $types->current()->getName());
376 771 mapi }
377 782 mapi
378 mapi /**
379 mapi * Tests that the parser adds a function to a declared namespace.
380 mapi *
381 mapi * @return void
382 1041 mapi * @covers PHP_Depend_Parser
383 mapi * @group pdepend
384 mapi * @group pdepend::issues
385 mapi * @group pdepend::parser
386 mapi * @group unittest
387 782 mapi */
388 mapi public function testParserAddsFunctionToDeclaredNamespaceSemicolonSyntax()
389 mapi {
390 mapi $packages = self::parseSource('issues/002-014-namespace-function.php');
391 mapi $function = $packages->current()
392 mapi ->getFunctions()
393 mapi ->current();
394 mapi
395 mapi $this->assertSame('foo\bar', $function->getPackage()->getName());
396 mapi }
397 mapi
398 mapi /**
399 786 mapi * Tests that the parser expands a local name within the signature of a
400 mapi * namespace class or interface correct.
401 mapi *
402 mapi * @param string $fileName Name of the test file.
403 mapi * @param string $namespaceName Name of the expected namespace.
404 mapi *
405 mapi * @return void
406 1041 mapi * @covers PHP_Depend_Parser
407 mapi * @group pdepend
408 mapi * @group pdepend::issues
409 mapi * @group pdepend::parser
410 mapi * @group unittest
411 786 mapi * @dataProvider dataProviderParserResolvesQualifiedTypeNameInTypeSignature
412 mapi */
413 mapi public function testParserResolvesQualifiedTypeNameInTypeSignature($fileName, $namespaceName)
414 mapi {
415 mapi $packages = self::parseSource($fileName);
416 mapi $type = $packages->current()
417 mapi ->getTypes()
418 mapi ->current();
419 mapi
420 mapi $dependency = $type->getDependencies()->current();
421 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
422 mapi }
423 mapi
424 mapi /**
425 783 mapi * Tests that the parser expands a local name within the body of a
426 782 mapi * namespaced function correct.
427 mapi *
428 785 mapi * @param string $fileName Name of the test file.
429 mapi * @param string $namespaceName Name of the expected namespace.
430 mapi *
431 782 mapi * @return void
432 1041 mapi * @covers PHP_Depend_Parser
433 mapi * @group pdepend
434 mapi * @group pdepend::issues
435 mapi * @group pdepend::parser
436 mapi * @group unittest
437 786 mapi * @dataProvider dataProviderParserResolvesQualifiedTypeNameInFunction
438 782 mapi */
439 786 mapi public function testParserResolvesQualifiedTypeNameInFunction($fileName, $namespaceName)
440 782 mapi {
441 785 mapi $packages = self::parseSource($fileName);
442 782 mapi $function = $packages->current()
443 mapi ->getFunctions()
444 mapi ->current();
445 mapi
446 mapi $dependency = $function->getDependencies()
447 mapi ->current();
448 mapi
449 785 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
450 mapi $this->assertContains($function->getPackage()->getName(),
451 mapi $dependency->getPackage()->getName());
452 782 mapi }
453 783 mapi
454 mapi /**
455 786 mapi * Tests that the parser does not expand a qualified name within the
456 mapi * signature of a namespaced class or interface correct.
457 mapi *
458 mapi * @param string $fileName Name of the test file.
459 mapi * @param string $namespaceName Name of the expected namespace.
460 mapi *
461 mapi * @return void
462 1041 mapi * @covers PHP_Depend_Parser
463 mapi * @group pdepend
464 mapi * @group pdepend::issues
465 mapi * @group pdepend::parser
466 mapi * @group unittest
467 786 mapi * @dataProvider dataProviderParserKeepsQualifiedTypeNameInTypeSignature
468 mapi */
469 mapi public function testParserKeepsQualifiedTypeNameInTypeSignature($fileName, $namespaceName)
470 mapi {
471 mapi $packages = self::parseSource($fileName);
472 mapi $type = $packages->current()
473 mapi ->getTypes()
474 mapi ->current();
475 mapi
476 mapi $dependency = $type->getDependencies()->current();
477 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
478 mapi }
479 mapi
480 mapi /**
481 783 mapi * Tests that the parser does not expand a qualified name within the body of
482 mapi * a namespaced function correct.
483 mapi *
484 785 mapi * @param string $fileName Name of the test file.
485 mapi * @param string $namespaceName Name of the expected namespace.
486 mapi *
487 783 mapi * @return void
488 1041 mapi * @covers PHP_Depend_Parser
489 mapi * @group pdepend
490 mapi * @group pdepend::issues
491 mapi * @group pdepend::parser
492 mapi * @group unittest
493 786 mapi * @dataProvider dataProviderParserKeepsQualifiedTypeNameInFunction
494 783 mapi */
495 786 mapi public function testParserKeepsQualifiedTypeNameInFunction($fileName, $namespaceName)
496 783 mapi {
497 785 mapi $packages = self::parseSource($fileName);
498 783 mapi
499 mapi // Get namespaced function
500 mapi $function = $packages->current()
501 853 mapi ->getFunctions()
502 mapi ->current();
503 783 mapi
504 mapi $dependency = $function->getDependencies()
505 853 mapi ->current();
506 783 mapi
507 853 mapi $this->assertType('PHP_Depend_Code_Class', $dependency);
508 785 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
509 783 mapi }
510 784 mapi
511 mapi /**
512 mapi * Tests that the parser resolves a type name when the name is prefixed with
513 mapi * PHP's namespace keyword.
514 mapi *
515 785 mapi * @param string $fileName Name of the test file.
516 mapi * @param string $namespaceName Name of the expected namespace.
517 mapi *
518 784 mapi * @return void
519 1041 mapi * @covers PHP_Depend_Parser
520 mapi * @group pdepend
521 mapi * @group pdepend::issues
522 mapi * @group pdepend::parser
523 mapi * @group unittest
524 787 mapi * @dataProvider dataProviderParserResolvesNamespaceKeywordInTypeSignatureSemicolonSyntax
525 mapi */
526 mapi public function testParserResolvesNamespaceKeywordInTypeSignatureSemicolonSyntax($fileName, $namespaceName)
527 mapi {
528 mapi $packages = self::parseSource($fileName);
529 mapi $type = $packages->current()
530 mapi ->getTypes()
531 mapi ->current();
532 mapi
533 mapi $dependency = $type->getDependencies()->current();
534 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
535 mapi }
536 mapi
537 mapi /**
538 mapi * Tests that the parser resolves a type name when the name is prefixed with
539 mapi * PHP's namespace keyword.
540 mapi *
541 mapi * @param string $fileName Name of the test file.
542 mapi * @param string $namespaceName Name of the expected namespace.
543 mapi *
544 mapi * @return void
545 1041 mapi * @covers PHP_Depend_Parser
546 mapi * @group pdepend
547 mapi * @group pdepend::issues
548 mapi * @group pdepend::parser
549 mapi * @group unittest
550 786 mapi * @dataProvider dataProviderParserResolvesNamespaceKeywordInFunctionSemicolonSyntax
551 784 mapi */
552 786 mapi public function testParserResolvesNamespaceKeywordInFunctionSemicolonSyntax($fileName, $namespaceName)
553 784 mapi {
554 785 mapi $packages = self::parseSource($fileName);
555 784 mapi $function = $packages->current()
556 mapi ->getFunctions()
557 mapi ->current();
558 mapi
559 mapi $dependency = $function->getDependencies()
560 mapi ->current();
561 mapi
562 785 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
563 784 mapi }
564 mapi
565 mapi /**
566 mapi * Tests that the parser resolves a type name when the name is prefixed with
567 mapi * PHP's namespace keyword.
568 mapi *
569 785 mapi * @param string $fileName Name of the test file.
570 mapi * @param string $namespaceName Name of the expected namespace.
571 mapi *
572 784 mapi * @return void
573 1041 mapi * @covers PHP_Depend_Parser
574 mapi * @group pdepend
575 mapi * @group pdepend::issues
576 mapi * @group pdepend::parser
577 mapi * @group unittest
578 787 mapi * @dataProvider dataProviderParserResolvesNamespaceKeywordInTypeSignatureCurlyBraceSyntax
579 mapi */
580 mapi public function testParserResolvesNamespaceKeywordInTypeSignatureCurlyBraceSyntax($fileName, $namespaceName)
581 mapi {
582 mapi $packages = self::parseSource($fileName);
583 mapi $type = $packages->current()
584 mapi ->getTypes()
585 mapi ->current();
586 mapi
587 mapi $dependency = $type->getDependencies()->current();
588 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
589 mapi }
590 mapi
591 mapi /**
592 mapi * Tests that the parser resolves a type name when the name is prefixed with
593 mapi * PHP's namespace keyword.
594 mapi *
595 mapi * @param string $fileName Name of the test file.
596 mapi * @param string $namespaceName Name of the expected namespace.
597 mapi *
598 mapi * @return void
599 1041 mapi * @covers PHP_Depend_Parser
600 mapi * @group pdepend
601 mapi * @group pdepend::issues
602 mapi * @group pdepend::parser
603 mapi * @group unittest
604 786 mapi * @dataProvider dataProviderParserResolvesNamespaceKeywordInFunctionCurlyBraceSyntax
605 784 mapi */
606 786 mapi public function testParserResolvesNamespaceKeywordInFunctionCurlyBraceSyntax($fileName, $namespaceName)
607 784 mapi {
608 785 mapi $packages = self::parseSource($fileName);
609 784 mapi $function = $packages->current()
610 mapi ->getFunctions()
611 mapi ->current();
612 mapi
613 mapi $dependency = $function->getDependencies()
614 mapi ->current();
615 mapi
616 785 mapi $this->assertSame($namespaceName, $dependency->getPackage()->getName());
617 784 mapi }
618 785 mapi
619 mapi /**
620 mapi * Data provider method that returns test data for class name resolving
621 mapi * tests.
622 mapi *
623 mapi * @return array
624 mapi */
625 787 mapi public static function dataProviderParserResolvesQualifiedTypeNameInFunction()
626 785 mapi {
627 mapi return array(
628 787 mapi array('issues/002-015-resolve-qualified-type-names.php', 'foo\bar'),
629 mapi array('issues/002-019-resolve-qualified-type-names.php', 'foo\bar'),
630 mapi array('issues/002-023-resolve-qualified-type-names.php', 'foo\baz'),
631 mapi array('issues/002-027-resolve-qualified-type-names.php', 'foo\bar'),
632 789 mapi array('issues/002-047-resolve-qualified-type-names.php', 'foo\foo'),
633 mapi array('issues/002-051-resolve-qualified-type-names.php', 'baz\baz'),
634 786 mapi );
635 mapi }
636 mapi
637 mapi /**
638 mapi * Data provider method that returns test data for class name resolving
639 mapi * tests.
640 mapi *
641 mapi * @return array
642 mapi */
643 787 mapi public static function dataProviderParserResolvesQualifiedTypeNameInTypeSignature()
644 786 mapi {
645 mapi return array(
646 787 mapi array('issues/002-031-resolve-qualified-type-names.php', 'baz'),
647 mapi array('issues/002-035-resolve-qualified-type-names.php', 'baz'),
648 mapi array('issues/002-039-resolve-qualified-type-names.php', 'baz'),
649 789 mapi array('issues/002-043-resolve-qualified-type-names.php', 'foo\bar'),
650 mapi array('issues/002-046-resolve-qualified-type-names.php', 'foo\foo'),
651 785 mapi );
652 mapi }
653 mapi
654 mapi /**
655 mapi * Data provider method that returns test data for class name resolving
656 mapi * tests.
657 mapi *
658 mapi * @return array
659 mapi */
660 786 mapi public static function dataProviderParserKeepsQualifiedTypeNameInFunction()
661 785 mapi {
662 mapi return array(
663 1307 mapi array('issues/002-016-resolve-qualified-type-names.php', ''),
664 mapi array('issues/002-020-resolve-qualified-type-names.php', ''),
665 786 mapi array('issues/002-024-resolve-qualified-type-names.php', 'baz'),
666 mapi array('issues/002-028-resolve-qualified-type-names.php', 'bar'),
667 789 mapi array('issues/002-048-resolve-qualified-type-names.php', 'foo'),
668 mapi array('issues/002-052-resolve-qualified-type-names.php', 'bar'),
669 785 mapi );
670 mapi }
671 mapi
672 mapi /**
673 mapi * Data provider method that returns test data for class name resolving
674 mapi * tests.
675 mapi *
676 mapi * @return array
677 mapi */
678 786 mapi public static function dataProviderParserKeepsQualifiedTypeNameInTypeSignature()
679 785 mapi {
680 mapi return array(
681 786 mapi array('issues/002-032-resolve-qualified-type-names.php', 'foo\bar'),
682 787 mapi array('issues/002-036-resolve-qualified-type-names.php', 'foo\bar'),
683 mapi array('issues/002-040-resolve-qualified-type-names.php', 'foo\bar'),
684 786 mapi );
685 mapi }
686 mapi
687 mapi /**
688 mapi * Data provider method that returns test data for class name resolving
689 mapi * tests.
690 mapi *
691 mapi * @return array
692 mapi */
693 mapi public static function dataProviderParserResolvesNamespaceKeywordInFunctionSemicolonSyntax()
694 mapi {
695 mapi return array(
696 785 mapi array('issues/002-017-resolve-qualified-type-names.php', 'foo\bar'),
697 mapi array('issues/002-021-resolve-qualified-type-names.php', 'foo\bar'),
698 mapi array('issues/002-025-resolve-qualified-type-names.php', 'foo\bar\baz'),
699 786 mapi array('issues/002-029-resolve-qualified-type-names.php', 'foo\bar\baz'),
700 789 mapi array('issues/002-049-resolve-qualified-type-names.php', 'bar\bar'),
701 785 mapi );
702 mapi }
703 mapi
704 mapi /**
705 mapi * Data provider method that returns test data for class name resolving
706 mapi * tests.
707 mapi *
708 mapi * @return array
709 mapi */
710 787 mapi public static function dataProviderParserResolvesNamespaceKeywordInTypeSignatureSemicolonSyntax()
711 mapi {
712 mapi return array(
713 mapi array('issues/002-033-resolve-qualified-type-names.php', 'baz\foo'),
714 mapi array('issues/002-037-resolve-qualified-type-names.php', 'baz\foo'),
715 mapi array('issues/002-041-resolve-qualified-type-names.php', 'baz\foo'),
716 789 mapi array('issues/002-044-resolve-qualified-type-names.php', 'foo\foo'),
717 787 mapi );
718 mapi }
719 mapi
720 mapi /**
721 mapi * Data provider method that returns test data for class name resolving
722 mapi * tests.
723 mapi *
724 mapi * @return array
725 mapi */
726 786 mapi public static function dataProviderParserResolvesNamespaceKeywordInFunctionCurlyBraceSyntax()
727 785 mapi {
728 mapi return array(
729 1307 mapi array('issues/002-018-resolve-qualified-type-names.php', ''),
730 mapi array('issues/002-022-resolve-qualified-type-names.php', ''),
731 785 mapi array('issues/002-026-resolve-qualified-type-names.php', 'baz'),
732 786 mapi array('issues/002-030-resolve-qualified-type-names.php', 'baz'),
733 789 mapi array('issues/002-050-resolve-qualified-type-names.php', 'baz\baz'),
734 785 mapi );
735 mapi }
736 787 mapi
737 mapi /**
738 mapi * Data provider method that returns test data for class name resolving
739 mapi * tests.
740 mapi *
741 mapi * @return array
742 mapi */
743 mapi public static function dataProviderParserResolvesNamespaceKeywordInTypeSignatureCurlyBraceSyntax()
744 mapi {
745 mapi return array(
746 mapi array('issues/002-034-resolve-qualified-type-names.php', 'baz\foo'),
747 mapi array('issues/002-038-resolve-qualified-type-names.php', 'baz\foo'),
748 788 mapi array('issues/002-042-resolve-qualified-type-names.php', 'baz\foo'),
749 789 mapi array('issues/002-045-resolve-qualified-type-names.php', 'foo\foo'),
750 787 mapi );
751 mapi }
752 735 mapi }