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.
Bug Report
AddSeeTestAnnotationRectoradds a second@seeannotation when the first one is imported rather than fully qualified.The rule writes
@see \App\Tests\FooTest. php-cs-fixer'sfully_qualified_strict_types, which PER-CS enables, then shortens that to@see FooTestand adds ause. 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\FooTestpresent andrectorPreset: true:/** * @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
usestatements before comparing would do it.