Skip to content

SeeAnnotationToTestRule doesn't resolve imported class names #377

Closed

Description

@Brainshaker95

We import our test classes and reference them by their short name:

use Acme\Tests\User\UserMailerTest;

/**
 * @see UserMailerTest
 */
final class UserMailer {}

This reports Class "Acme\User\UserMailer" is missing @see annotation with test case class reference. Writing @see \Acme\Tests\User\UserMailerTest passes, but php-cs-fixer's fully_qualified_strict_types with import_symbols shortens it again on the next run.

The rule hands the raw tag text to is_a(), so a short name never matches:

private function hasSeeTestCaseAnnotation(array $seeTags): bool
{
foreach ($seeTags as $seeTag) {
if (! $seeTag->value instanceof GenericTagValueNode) {
continue;
}
if (is_a($seeTag->value->value, TestClassName::PHPUNIT_TEST_CASE, true)) {
return true;
}
}
return false;
}

Resolving it through the docblock's name scope first, e.g. with getNullableNameScope()->resolveStringName(), would fix it.

Rector's AddSeeTestAnnotationRector had the same problem (rectorphp/rector#9875), fixed in rectorphp/rector-phpunit#779.

Version: symplify/phpstan-rules 14.19.1

Activity

  1. TomasVotruba commented on Oct 17, 2026

    @TomasVotruba
    Member

    Thank you for your report!

    We'll need an isolated failing demo link from: http://getrector.com/demo,
    that way we can reproduce the bug.

  2. Brainshaker95 commented on Oct 18, 2026

    @Brainshaker95
    ContributorAuthor

    This one is a PHPStan rule, so the Rector demo can't run it. The snippet above reproduces it with SeeAnnotationToTestRule enabled.

  3. TomasVotruba commented on Oct 18, 2026

    @TomasVotruba
    Member

    Ah, sorry, wrong repo. Can you send failing test PR with fixture then?

  4. Brainshaker95 commented on Oct 18, 2026

    @Brainshaker95
    ContributorAuthor

    No worries! The failing fixture is up in #378.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions