Skip to content

Commit

Permalink
Merge pull request #265 from sensiolabs-de/bugfix/resovle-class-names…
Browse files Browse the repository at this point in the history
…cope

Bugfix: classes in other namespaces are resolved in same namespace
  • Loading branch information
Simon Mönch committed Sep 20, 2019
2 parents 47dc838 + a006d50 commit 9e85f7e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AstRunner/Resolver/NameScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function resolveStringName(string $name): string
}

$nameParts = explode('\\', $name);
$firstNamePart = strtolower($nameParts[0]);
$firstNamePart = $nameParts[0];

if (isset($this->uses[$firstNamePart])) {
if (1 === count($nameParts)) {
Expand Down
25 changes: 25 additions & 0 deletions tests/AstRunner/NameScopeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Tests\SensioLabs\Deptrac\AstRunner;

use PHPUnit\Framework\TestCase;
use SensioLabs\Deptrac\AstRunner\AstMap\AstDependency;
use SensioLabs\Deptrac\AstRunner\AstMap\AstFileReference;
use SensioLabs\Deptrac\AstRunner\Resolver\NameScope;

class NameScopeTest extends TestCase
{
public function testResolveStringName(): void
{
$fileReference = new AstFileReference('baz.php');
$fileReference->addDependency(AstDependency::useStmt('FooBar\OtherNamespace\OtherNamespaceClass', 1));
$classReference = $fileReference->addClassReference('FooBar\Baz');

$nameScope = new NameScope($classReference);

static::assertSame('FooBar\SameNamespaceClass', $nameScope->resolveStringName('SameNamespaceClass'));
static::assertSame('FooBar\OtherNamespace\OtherNamespaceClass', $nameScope->resolveStringName('OtherNamespaceClass'));
}
}

0 comments on commit 9e85f7e

Please sign in to comment.