Skip to content

Commit

Permalink
fixt test
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Jun 15, 2020
1 parent 6e1f39d commit f78ee97
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/GlobalNameClassWatchVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GlobalNameClassWatchVisitor extends NodeVisitorAbstract

public function enterNode(Node $node) : void
{
if ($node instanceof Node\Name\Use_ && count($node->parts) === 1) {
if ($node instanceof Node\Name\FullyQualified && count($node->parts) === 1) {
$target = $node->parts[0];
$isGlobalClassName = ! function_exists($target) && ! defined($target);
if ($isGlobalClassName && ! in_array($target, $this->globalClassNames, true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Spaceman.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function resolveName($ast) : array
$nodeTraverser->addVisitor($watchVisitor);
$travesedAst = $nodeTraverser->traverse($ast);

return $this->importGlobalClass($watchVisitor->globalClassNames, $travesedAst);
return $this->importGlobalClass(array_unique($watchVisitor->globalClassNames), $travesedAst);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Fake/Fake.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public function run()
{
new Author;
new Bar;
new LogicException;
}
}
4 changes: 3 additions & 1 deletion tests/SpacemanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test__invoke() : void
}
$namespace = 'Newname\Space';
$sourceCode = ($this->spaceman)($code, $namespace);
$expected = <<<'EOT'
$expected = /** @lang php */<<<EOT
<?php
namespace Newname\Space;
Expand All @@ -44,8 +44,10 @@ public function run()
{
new Author;
new \Foo\Bar;
new LogicException;
}
}
use Author, LogicException;
EOT;
$this->assertSame($expected, $sourceCode);
Expand Down

0 comments on commit f78ee97

Please sign in to comment.