Skip to content

AddSeeTestAnnotationRector adds a duplicate @see when the existing annotation is imported #9875

Description

@Brainshaker95

Bug Report

Subject Details
Rector version v2.6.5

AddSeeTestAnnotationRector adds a second @see annotation when the first one is imported rather than fully qualified.

The rule writes @see \App\Tests\FooTest. php-cs-fixer's fully_qualified_strict_types, which PER-CS enables, then shortens that to @see FooTest and adds a use. On the next run the rule no longer recognizes its own annotation and appends another, so the count grows on every run.

hasAlreadySeeAnnotation() compares the raw docblock text against the fully qualified name, so the short form never matches:

https://github.com/rectorphp/rector-phpunit/blob/c4e571ee6d61aa0bf68346bab12b85e2df3aead2/rules/CodeQuality/Rector/Class_/AddSeeTestAnnotationRector.php#L164-L169

This was reported once before in #9795 and closed because the reporter's test classes turned out to be in the wrong namespace, so the reproduction never held up. The one below does — the test class is found, which is what makes the rule add the duplicate.

Minimal PHP Code Causing Issue

With App\Tests\FooTest present and rectorPreset: true:

namespace App;

use App\Tests\FooTest;

/**
 * @see FooTest
 */
final class Foo {}
 /**
  * @see FooTest
+ * @see \App\Tests\FooTest
  */

Expected Behaviour

Skip the class — the annotation is already there, just imported. Resolving the name against the file's use statements before comparing would do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions