Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Rules/SeeAnnotationToTestRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Rules/SeeAnnotationToTestRule/Fixture/SkipImportedSee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\SeeAnnotationToTestRule\Fixture;

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use Symplify\PHPStanRules\Tests\Rules\SeeAnnotationToTestRule\SeeAnnotationToTestRuleTest;

/**
* @see SeeAnnotationToTestRuleTest
*/
final class SkipImportedSee implements Rule
{
public function getNodeType(): string
{
}

public function processNode(Node $node, Scope $scope): array
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/RuleWithSeeRandom.php', [[$errorMessage, 15]]];

yield [__DIR__ . '/Fixture/SkipDeprecatedRuleWithoutSee.php', []];
yield [__DIR__ . '/Fixture/SkipImportedSee.php', []];
}

/**
Expand Down
Loading