rectorphp / rector-phpunit

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

Add new rector rule to add `#[CoversClass()]` to test classes #318

Closed maks-rafalko closed 5 months ago

maks-rafalko commented 6 months ago

Desired behavior:

+ #[CoversClass(SomeService::class)]
class SomeServiceTest extends TestCase
{
}

Actually, I've already implemented it as a custom rule as we need it in Infection. It works great and covered by tests

https://github.com/infection/infection/commit/03da55739a01e38f2ddf3dbef9f0f7e6adf53f42#diff-8a5ee371c08d2d066c7dfe04dea926a679e3ff5fb35ff93a228aa2a5c46e3699R65

But I would like to integrate it into rector/rector-phpunit itself, as I'm pretty sure it will be useful for other teams that would like to automatically add #[CoversClass()] to their test classes and automatically guess source file used as a value of this attribute. This is pretty convenient, and existing tools, including PHP-CS-Fixer, doesn't help with it.

But before creating a PR, I would like to know if it's going to be accepted to not waste time.

Also, this issue will popup in a search so even if it's not going to be accepted, one will have a link to a custom implementation.

TomasVotruba commented 6 months ago

Looks good :+1:

Please send the PR :)

maks-rafalko commented 6 months ago

Ready for review: https://github.com/rectorphp/rector-phpunit/pull/319