diff --git a/src/Rules/SeeAnnotationToTestRule.php b/src/Rules/SeeAnnotationToTestRule.php index 4dc038216..de91c805c 100644 --- a/src/Rules/SeeAnnotationToTestRule.php +++ b/src/Rules/SeeAnnotationToTestRule.php @@ -7,6 +7,7 @@ use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use PHPStan\Analyser\NameScope; use PHPStan\Analyser\Scope; use PHPStan\Node\InClassNode; use PHPStan\PhpDoc\Tag\DeprecatedTag; @@ -94,7 +95,7 @@ public function processNode(Node $node, Scope $scope): array } $seeTags = $this->seePhpDocTagNodesFinder->find($resolvedPhpDocBlock); - if ($this->hasSeeTestCaseAnnotation($seeTags)) { + if ($this->hasSeeTestCaseAnnotation($seeTags, $resolvedPhpDocBlock->getNullableNameScope())) { return []; } @@ -123,14 +124,19 @@ private function shouldSkipClassReflection(ClassReflection $classReflection): bo /** * @param PhpDocTagNode[] $seeTags */ - private function hasSeeTestCaseAnnotation(array $seeTags): bool + private function hasSeeTestCaseAnnotation(array $seeTags, ?NameScope $nameScope): bool { foreach ($seeTags as $seeTag) { if (! $seeTag->value instanceof GenericTagValueNode) { continue; } - if (is_a($seeTag->value->value, TestClassName::PHPUNIT_TEST_CASE, true)) { + // resolve short imported names to fully qualified ones + $className = $nameScope instanceof NameScope + ? $nameScope->resolveStringName($seeTag->value->value) + : $seeTag->value->value; + + if (is_a($className, TestClassName::PHPUNIT_TEST_CASE, true)) { return true; } } diff --git a/tests/Rules/SeeAnnotationToTestRule/Fixture/SkipImportedSee.php b/tests/Rules/SeeAnnotationToTestRule/Fixture/SkipImportedSee.php new file mode 100644 index 000000000..176148f08 --- /dev/null +++ b/tests/Rules/SeeAnnotationToTestRule/Fixture/SkipImportedSee.php @@ -0,0 +1,24 @@ +