rectorphp / rector-phpunit

Rector upgrade rules for PHPUnit
https://getrector.com/find-rule?activeRectorSetGroup=phpunit
MIT License
68 stars 47 forks source link

Would it be possible for AnnotationToAttributeRector to check if the annotation is already there? #183

Closed HenkPoley closed 1 year ago

HenkPoley commented 1 year ago

I'm currently seeing some "fighting" between php-cs-fixer adding @coversNothing, and then rector removing it and adding the annotation (again).

I can suppress @coversNothing at php-cs-fixer, but annotations shouldn't be doubled up.

https://github.com/rectorphp/rector-phpunit/blob/71fabfb51087ff0e6c97ad0296e20ff3634b9008/config/sets/annotations-to-attributes.php#L91

Would add

#[PHPUnit\Framework\Attributes\CoversNothing]
TomasVotruba commented 1 year ago

Hi, in this case you have to ignore the rule in one of the tools, as the intentions are countering each other.

I recommend using Rector to handle the upgrade and coding standard tools the looks of code. It works very well when they each take care of the area they handle best and cooperate :)

HenkPoley commented 1 year ago

I'm not quite sure if they are counteracting each other.

My issue was mainly that it results in:

#[PHPUnit\Framework\Attributes\CoversNothing]
#[PHPUnit\Framework\Attributes\CoversNothing]
..or more..

Since it will blindly try to "re-"add the attribute.

I mean, I guess you could say that Rector always needs supervision, so breaking the PHP file is okeydokey. But a filter to the attribute add function resolves this for other part as well.

TomasVotruba commented 1 year ago

I see. Maybe it would be better to have test fixture right here without any other tool. To see if it's something we can fix :)

Could you send a PR with your failing test case?