Skip to content

Commit

Permalink
Fix and testcase for inline namespace usage
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Feb 26, 2011
1 parent 72f8c6e commit 112339f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/classfinder.php
Expand Up @@ -86,7 +86,7 @@ public function parseFile($file) {
$dependsClass = '';

$token = token_get_all(file_get_contents($file));
foreach($token as $tok) {
foreach($token as $pos => $tok) {
if (!is_array($tok)) {
switch ($tok) {
case '{': {
Expand Down Expand Up @@ -159,6 +159,10 @@ public function parseFile($file) {
continue;
}
case T_NAMESPACE: {
if ($token[$pos + 1][0] == T_NS_SEPARATOR) {
// Ignore inline use of namespace keyword
continue;
}
$nsFound = true;
$nsProc = true;
$inNamespace = null;
Expand Down
12 changes: 12 additions & 0 deletions tests/_data/classfinder/namespaceconstant.php
@@ -0,0 +1,12 @@
<?php

namespace demo\level2 {

var_dump(namespace\foo);

class demo1 { }

}


?>
12 changes: 10 additions & 2 deletions tests/classfinder.test.php
Expand Up @@ -61,7 +61,7 @@ public function testOneClass() {
}

/**
*
*
* @expectedException \TheSeer\Tools\ClassFinderException
* @expectedExceptionCode \TheSeer\Tools\ClassFinderException::ClassRedeclaration
*/
Expand All @@ -70,7 +70,7 @@ public function testRedeclaringThrowsException() {
$finder->parseFile(__DIR__.'/_data/classfinder/class.php');
$finder->parseFile(__DIR__.'/_data/classfinder/class.php');
}

public function testFullPathToClass() {
$finder = new \TheSeer\Tools\ClassFinder;
$rc = $finder->parseFile(__DIR__.'/_data/classfinder/class.php');
Expand Down Expand Up @@ -176,6 +176,14 @@ public function testNamespaceBracketSyntaxMultiNS() {
$this->assertArrayHasKey('demo\\\\level2\\\\level3\\\\demo2', $classes);
}

public function testNamespaceParsingIgnoresConstantAccessUseOfNamespaceKeyword() {
$finder = new \TheSeer\Tools\ClassFinder;
$rc = $finder->parseFile(__DIR__.'/_data/classfinder/namespaceconstant.php');
$this->assertEquals(1,$rc);
$classes = $finder->getClasses();
$this->assertArrayHasKey('demo\\\\level2\\\\demo1', $classes);
}

public function testBracketParsingBugTest1() {
$finder = new \TheSeer\Tools\ClassFinder;
$rc = $finder->parseFile(__DIR__.'/_data/classfinder/brackettest1.php');
Expand Down

0 comments on commit 112339f

Please sign in to comment.