rectorphp / rector-phpunit

Rector upgrade rules for PHPUnit
http://getrector.com
MIT License
61 stars 46 forks source link

AddCoversClassAttributeRector: Support *TestCase suffix #324

Closed staabm closed 2 months ago

staabm commented 2 months ago

In some projects (e.g. PHPUnit itself) testcase-names are ending in TestCase not just Test

running the new rector on phpunit itself yields a few false positives, e.g.

55) tests/unit/Framework/MockObject/TestDoubleTestCase.php:21

    ---------- begin diff ----------
@@ @@
 use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
 use stdClass;

+#[\PHPUnit\Framework\Attributes\CoversClass(\PHPUnit\Framework\MockObject\TestDoubleTestCase::class)]
 abstract class TestDoubleTestCase extends TestCase
 {
     final public function testMethodReturnsNullWhenReturnValueIsNullableAndNoReturnValueIsConfigured(): void
    ----------- end diff -----------

Applied rules:
 * AddCoversClassAttributeRector

56) tests/unit/Metadata/Parser/AnnotationParserTestCase.php:41

    ---------- begin diff ----------
@@ @@
 use PHPUnit\TestFixture\Metadata\Annotation\TestDoxTest;
 use PHPUnit\TestFixture\Metadata\Annotation\UsesTest;

+#[\PHPUnit\Framework\Attributes\CoversClass(\PHPUnit\Metadata\Parser\AnnotationParserTestCase::class)]
 abstract class AnnotationParserTestCase extends TestCase
 {
     public static function provideRequiresPhpTestMethods(): array
    ----------- end diff -----------

Applied rules:
 * AddCoversClassAttributeRector

57) tests/unit/Metadata/Parser/AttributeParserTestCase.php:52

    ---------- begin diff ----------
@@ @@
 use PHPUnit\TestFixture\Metadata\Attribute\UsesTest;
 use PHPUnit\TestFixture\Metadata\Attribute\WithoutErrorHandlerTest;

+#[\PHPUnit\Framework\Attributes\CoversClass(\PHPUnit\Metadata\Parser\AttributeParserTestCase::class)]
 abstract class AttributeParserTestCase extends TestCase
 {
     #[TestDox('Parses #[BackupGlobals] attribute on class')]
    ----------- end diff -----------

Applied rules:
 * AddCoversClassAttributeRector

refs https://github.com/rectorphp/rector-phpunit/pull/319#issuecomment-2053952839

staabm commented 2 months ago

after this PR it now correctly yields:

4) tests/unit/Metadata/Parser/AttributeParserTestCase.php:52

    ---------- begin diff ----------
@@ @@
 use PHPUnit\TestFixture\Metadata\Attribute\UsesTest;
 use PHPUnit\TestFixture\Metadata\Attribute\WithoutErrorHandlerTest;

+#[\PHPUnit\Framework\Attributes\CoversClass(\PHPUnit\Metadata\Parser\AttributeParser::class)]
 abstract class AttributeParserTestCase extends TestCase
 {
     #[TestDox('Parses #[BackupGlobals] attribute on class')]
    ----------- end diff -----------

Applied rules:
 * AddCoversClassAttributeRector

5) tests/unit/TextUI/Configuration/Xml/MigratorTest.php:12

    ---------- begin diff ----------
@@ @@
 use PHPUnit\Framework\TestCase;
 use PHPUnit\Util\Xml\Loader as XmlLoader;

+#[\PHPUnit\Framework\Attributes\CoversClass(\PHPUnit\TextUI\XmlConfiguration\Migrator::class)]
 final class MigratorTest extends TestCase
 {
     #[TestDox('Can migrate PHPUnit 9.2 configuration')]
    ----------- end diff -----------

Applied rules:
 * AddCoversClassAttributeRector
samsonasik commented 2 months ago

Thank you @staabm