Arbit - project tracking

PHP Depend

History

Diff

1038 1039 /tests/PHP/Depend/ParserTest.php
1227 1227 }
1228 1228
1229 1229 /**
1230 + * testParserStripsLeadingSlashFromNamespacedClassName
1231 + *
1232 + * @return void
1233 + * @covers PHP_Depend_Parser::_getNamespaceOrPackageName
1234 + * @group pdepend
1235 + * @group pdepend::parser
1236 + * @group unittest
1237 + */
1238 + public function testParserStripsLeadingSlashFromNamespacedClassName()
1239 + {
1240 + $packages = self::parseSource('parser/' . __FUNCTION__ . '.php');
1241 + $package = $packages->current();
1242 +
1243 + $this->assertEquals('foo', $package->getName());
1244 + }
1245 +
1246 + /**
1247 + * testParserStripsLeadingSlashFromNamespacedClassName
1248 + *
1249 + * @return void
1250 + * @covers PHP_Depend_Parser::_getNamespaceOrPackageName
1251 + * @group pdepend
1252 + * @group pdepend::parser
1253 + * @group unittest
1254 + */
1255 + public function testParserStripsLeadingSlashFromNamespaceAliasedClassName()
1256 + {
1257 + $packages = self::parseSource('parser/' . __FUNCTION__ . '.php');
1258 + $package = $packages->current()
1259 + ->getClasses()
1260 + ->current()
1261 + ->getParentClass()
1262 + ->getPackage();
1263 +
1264 + $this->assertEquals('foo\bar\baz', $package->getName());
1265 + }
1266 +
1267 + /**
1268 + * testParserStripsLeadingSlashFromInheritNamespacedClassName
1269 + *
1270 + * @return void
1271 + * @covers PHP_Depend_Parser::_parseQualifiedName
1272 + * @group pdepend
1273 + * @group pdepend::parser
1274 + * @group unittest
1275 + */
1276 + public function testParserStripsLeadingSlashFromInheritNamespacedClassName()
1277 + {
1278 + $packages = self::parseSource('parser/' . __FUNCTION__ . '.php');
1279 + $package = $packages->current()
1280 + ->getClasses()
1281 + ->current()
1282 + ->getParentClass()
1283 + ->getPackage();
1284 +
1285 + $this->assertEquals('bar', $package->getName());
1286 + }
1287 +
1288 + /**
1230 1289 * Tests that the parser ignores variable class instantiation.
1231 1290 *
1232 1291 * http://bugs.xplib.de/index.php?do=details&task_id=10&project=3
1443 1502 array(PHP_Depend_TokenizerI::T_CURLY_BRACE_CLOSE, 34),
1444 1503 );
1445 1504
1505 + $actual = array();
1446 1506 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]);
1507 + $actual[] = array($token->type, $token->startLine);
1451 1508 }
1452 -
1453 - $this->assertSame(0, count($expected));
1509 + $this->assertSame($expected, $actual);
1454 1510 }
1455 1511
1456 1512 /**
1038 1039 /tests/PHP/Depend/Bugs/AllTests.php
75 75 require_once dirname(__FILE__) . '/ParserSetsIncorrectStartLineBug101Test.php';
76 76 require_once dirname(__FILE__) . '/NamespaceKeywordInParameterTypeHintBug102Test.php';
77 77 require_once dirname(__FILE__) . '/ParameterStringDefaultValueBug103Test.php';
78 +require_once dirname(__FILE__) . '/DefaultNamespaceBug106Test.php';
78 79
79 80 /**
80 81 * Test suite for bugs meta package.
130 131 $suite->addTestSuite('PHP_Depend_Bugs_ParserSetsIncorrectStartLineBug101Test');
131 132 $suite->addTestSuite('PHP_Depend_Bugs_NamespaceKeywordInParameterTypeHintBug102Test');
132 133 $suite->addTestSuite('PHP_Depend_Bugs_ParameterStringDefaultValueBug103Test');
134 + $suite->addTestSuite('PHP_Depend_Bugs_DefaultNamespaceBug106Test');
133 135
134 136 return $suite;
135 137 }
1038 1039 /tests/PHP/Depend/Bugs/DefaultNamespaceBug106Test.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 +require_once 'PHP/Depend.php';
53 +require_once 'PHP/Depend/Log/Summary/Xml.php';
54 +require_once 'PHP/Depend/Util/Type.php';
55 +
56 +/**
57 + * Test case for ticket #106, where internal classes appear in the metrics log
58 + * file.
59 + *
60 + * @category PHP
61 + * @package PHP_Depend
62 + * @subpackage Bugs
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://www.pdepend.org/
68 + */
69 +class PHP_Depend_Bugs_DefaultNamespaceBug106Test extends PHP_Depend_Bugs_AbstractTest
70 +{
71 + /**
72 + * testAllocatedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile
73 + *
74 + * @return void
75 + * @covers stdClass
76 + * @group pdepend
77 + * @group pdepend::bugs
78 + * @group regressiontest
79 + */
80 + public function testAllocatedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile()
81 + {
82 + $this->_runForTestCase(__METHOD__);
83 + }
84 +
85 + /**
86 + * testExtendedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile
87 + *
88 + * @return void
89 + * @covers stdClass
90 + * @group pdepend
91 + * @group pdepend::bugs
92 + * @group regressiontest
93 + */
94 + public function testExtendedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile()
95 + {
96 + $this->_runForTestCase(__METHOD__);
97 + }
98 +
99 + /**
100 + * Runs PHP_Depend with the summary logger, against a source file associated
101 + * with the given test case.
102 + *
103 + * @param string $testCase Name of the calling test case.
104 + *
105 + * @return void
106 + */
107 + private function _runForTestCase($testCase)
108 + {
109 + $uri = $this->createRunResourceURI(__FUNCTION__);
110 +
111 + $logger = new PHP_Depend_Log_Summary_Xml();
112 + $logger->setLogFile($uri);
113 +
114 + $pdepend = new PHP_Depend();
115 + $pdepend->addFile(self::getSourceFileForTestCase($testCase));
116 + $pdepend->addLogger($logger);
117 + $pdepend->analyze();
118 +
119 + $dom = new DOMDocument('1.0', 'UTF-8');
120 + $dom->load($uri);
121 +
122 + $xpath = new DOMXPath($dom);
123 + $result = $xpath->query('//class[@name="RuntimeException"]');
124 +
125 + $this->assertEquals(0, $result->length);
126 + }
127 +}
1038 1039 /tests/PHP/Depend/_code/bugs/106/testAllocatedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile.php
2 +<?php
3 +/**
4 + * @package foo
5 + */
6 +class testAllocatedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile
7 +{
8 + public function testAllocatedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile()
9 + {
10 + throw new \RuntimeException();
11 + }
12 +}
1038 1039 /tests/PHP/Depend/_code/bugs/106/testExtendedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile.php
2 +<?php
3 +/**
4 + * @package foo
5 + */
6 +class testExtendedInternalClassWithLeadingBackslashNotAppearsInSummaryLogFile extends \RuntimeException
7 +{
8 +}
1038 1039 /tests/PHP/Depend/_code/parser/testParserStripsLeadingSlashFromNamespaceAliasedClassName.php
2 +<?php
3 +namespace foo\bar;
4 +
5 +class testParserStripsLeadingSlashFromNamespaceAliasedClassName extends namespace\baz\FooBar {
6 +
7 +}
1038 1039 /tests/PHP/Depend/_code/parser/testParserStripsLeadingSlashFromInheritNamespacedClassName.php
2 +<?php
3 +namespace foo;
4 +
5 +class testParserStripsLeadingSlashFromNamespacedClassName extends \bar\Baz
6 +{
7 +
8 +}
1038 1039 /tests/PHP/Depend/_code/parser/testParserStripsLeadingSlashFromNamespacedClassName.php
2 +<?php
3 +namespace foo;
4 +
5 +class testParserStripsLeadingSlashFromNamespacedClassName extends \foo\Bar
6 +{
7 +
8 +}
1038 1039 /tests/PHP/Depend/Code/ASTInstanceOfExpressionTest.php
112 112 ->current()
113 113 ->getFunctions()
114 114 ->current(),
115 - '\foo\bar\Baz'
115 + 'foo\bar\Baz'
116 116 );
117 117 }
118 118
129 129 ->current()
130 130 ->getFunctions()
131 131 ->current(),
132 - '\foo\bar\Baz'
132 + 'foo\bar\Baz'
133 133 );
134 134 }
135 135
1038 1039 /tests/PHP/Depend/Issues/NamespaceSupportIssue002Test.php
551 551 public static function dataProviderParserKeepsQualifiedTypeNameInFunction()
552 552 {
553 553 return array(
554 - array('issues/002-016-resolve-qualified-type-names.php', ''),
555 - array('issues/002-020-resolve-qualified-type-names.php', ''),
554 + array('issues/002-016-resolve-qualified-type-names.php', '+global'),
555 + array('issues/002-020-resolve-qualified-type-names.php', '+global'),
556 556 array('issues/002-024-resolve-qualified-type-names.php', 'baz'),
557 557 array('issues/002-028-resolve-qualified-type-names.php', 'bar'),
558 558 array('issues/002-048-resolve-qualified-type-names.php', 'foo'),
617 617 public static function dataProviderParserResolvesNamespaceKeywordInFunctionCurlyBraceSyntax()
618 618 {
619 619 return array(
620 - array('issues/002-018-resolve-qualified-type-names.php', ''),
621 - array('issues/002-022-resolve-qualified-type-names.php', ''),
620 + array('issues/002-018-resolve-qualified-type-names.php', '+global'),
621 + array('issues/002-022-resolve-qualified-type-names.php', '+global'),
622 622 array('issues/002-026-resolve-qualified-type-names.php', 'baz'),
623 623 array('issues/002-030-resolve-qualified-type-names.php', 'baz'),
624 624 array('issues/002-050-resolve-qualified-type-names.php', 'baz\baz'),
1038 1039 /tests/PHP/Depend/Util/AllTests.php
46 46 * @link http://pdepend.org/
47 47 */
48 48
49 -if (defined('PHPUnit_MAIN_METHOD') === false) {
50 - define('PHPUnit_MAIN_METHOD', 'PHP_Depend_Util_AllTests::main');
51 -}
49 +require_once 'PHPUnit/Framework.php';
52 50
53 -require_once 'PHPUnit/Framework/TestSuite.php';
54 -require_once 'PHPUnit/TextUI/TestRunner.php';
55 -
56 51 require_once dirname(__FILE__) . '/FileUtilTest.php';
57 52 require_once dirname(__FILE__) . '/ImageConvertTest.php';
58 53 require_once dirname(__FILE__) . '/MathUtilTest.php';
54 +require_once dirname(__FILE__) . '/TypeTest.php';
59 55
60 56 /**
61 57 * Main test suite for the PHP_Depend_Util package.
71 67 class PHP_Depend_Util_AllTests
72 68 {
73 69 /**
74 - * Test suite main method.
75 - *
76 - * @return void
77 - */
78 - public static function main()
79 - {
80 - PHPUnit_TextUI_TestRunner::run(self::suite());
81 - }
82 -
83 - /**
84 70 * Creates the phpunit test suite for this package.
85 71 *
86 72 * @return PHPUnit_Framework_TestSuite
93 79 $suite->addTest(new PHP_Depend_Util_MathUtilTest());
94 80
95 81 $suite->addTestSuite('PHP_Depend_Util_ImageConvertTest');
82 + $suite->addTestSuite('PHP_Depend_Util_TypeTest');
96 83
97 84 return $suite;
98 85 }
99 -}
100 -
101 -if (PHPUnit_MAIN_METHOD === 'PHP_Depend_Util_AllTests::main') {
102 - PHP_Depend_Util_AllTests::main();
103 86 }
1038 1039 /tests/PHP/Depend/Util/TypeTest.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 Util
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/Util/Type.php';
53 +
54 +/**
55 + * Test case for type utility class.
56 + *
57 + * @category QualityAssurance
58 + * @package PHP_Depend
59 + * @subpackage Util
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_Util_TypeTest extends PHP_Depend_AbstractTest
67 +{
68 + /**
69 + * testIsInternalTypeDetectsInternalClassPrefixedWithBackslash
70 + *
71 + * @return void
72 + * @covers PHP_Depend_Util_Type::isInternalType
73 + * @group pdepend
74 + * @group pdepend::util
75 + * @group unittest
76 + */
77 + public function testIsInternalTypeDetectsInternalClassPrefixedWithBackslash()
78 + {
79 + $isInternal = PHP_Depend_Util_Type::isInternalType('\LogicException');
80 + $this->assertTrue($isInternal);
81 + }
82 +
83 + /**
84 + * testGetTypePackageReturnsExpectedExtensionNameForClassPrefixedWithBackslash
85 + *
86 + * @return void
87 + * @covers PHP_Depend_Util_Type::getTypePackage
88 + * @group pdepend
89 + * @group pdepend::util
90 + * @group unittest
91 + */
92 + public function testGetTypePackageReturnsExpectedExtensionNameForClassPrefixedWithBackslash()
93 + {
94 + $extensionName = PHP_Depend_Util_Type::getTypePackage('\LogicException');
95 + $this->assertEquals('+spl', $extensionName);
96 + }
97 +}
1038 1039 /PHP/Depend/Parser.php
3089 3089
3090 3090 // Check for fully qualified name
3091 3091 if ($fragments[0] === '\\') {
3092 - return join('', $fragments);
3092 + return ltrim(join('', $fragments), '\\');
3093 3093 }
3094 3094
3095 3095 // Search for an use alias
3104 3104 // Prepend current namespace
3105 3105 array_unshift($fragments, $this->_namespaceName, '\\');
3106 3106 }
3107 - return join('', $fragments);
3107 + return ltrim(join('', $fragments), '\\');
3108 3108 }
3109 3109
3110 3110 /**
3771 3771 */
3772 3772 private function _createQualifiedTypeName($localName)
3773 3773 {
3774 - return $this->_getNamespaceOrPackageName() . '\\' . $localName;
3774 + return ltrim($this->_getNamespaceOrPackageName() . '\\' . $localName, '\\');
3775 3775 }
3776 3776
3777 3777 /**
1038 1039 /PHP/Depend/Util/Type.php
206 206 {
207 207 self::_initTypeToExtension();
208 208
209 - return isset(self::$_typeNameToExtension[strtolower($typeName)]);
209 + $normalizedName = ltrim($typeName, '\\');
210 + $normalizedName = strtolower($normalizedName);
211 +
212 + return isset(self::$_typeNameToExtension[$normalizedName]);
210 213 }
211 214
212 215 /**
221 224 {
222 225 self::_initTypeToExtension();
223 226
224 - $typeName = strtolower($typeName);
225 - if (isset(self::$_typeNameToExtension[$typeName])) {
226 - return self::$_typeNameToExtension[$typeName];
227 + $normalizedName = ltrim($typeName, '\\');
228 + $normalizedName = strtolower($normalizedName);
229 + if (isset(self::$_typeNameToExtension[$normalizedName])) {
230 + return self::$_typeNameToExtension[$normalizedName];
227 231 }
228 232 return null;
229 233 }