Skip to content

Incorrect behavior of CoversAnnotationWithValueToAttributeRector #9183

@TimelessTron

Description

@TimelessTron

Bug Report

Subject Details
Rector version 2.0.16
PHP 8.3
PHPUnit 10.5.46
PHPStan 2.1.16
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/9330ed38-6292-464c-adf2-4b627bfd01d0

<?php

namespace App {
    trait SomeTrait {
    }
    class OtherStuff {
        public static function Inject(): void
        {}
    }
}

namespace App\Test {
    use App\SomeTrait;
    use PHPUnit\Framework\TestCase;

    /**
     * @covers \App\SomeTrait
     */
    final class SomeTraitTest extends TestCase
    {
        /**
         * @covers \App\OtherStuff::Inject
         */
        public function testYourThinks(): void
        {}
    }
}
<?php

     use App\SomeTrait;
     use PHPUnit\Framework\TestCase;
 
-    /**
-     * @covers \App\SomeTrait
-     */
+    #[\PHPUnit\Framework\Attributes\CoversTrait(\App\SomeTrait::class)]
+    #[\PHPUnit\Framework\Attributes\CoversMethod(\App\OtherStuff::class, 'Inject')]
     final class SomeTraitTest extends TestCase
     {
-        /**
-         * @covers \App\OtherStuff::Inject
-         */
         public function testYourThinks(): void
         {}
     }
 }
<?php

declare(strict_types=1);

use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withSets([
        PHPUnitSetList::PHPUNIT_100,
    ])
;

Responsible rules

  • CoversAnnotationWithValueToAttributeRector

Expected Behavior

In the code we see an example of a test. Covers are converted into anotations.
This was only partially implemented in PHPunit 10. The class CoversMethod was only added in PHPUnit 11.1.0

(sebastianbergmann/phpunit@3efde166f8370f1620a72f72c0c996a035cfe1f7)[https://github.com/sebastianbergmann/phpunit/commit/3efde166f8370f1620a72f72c0c996a035cfe1f7]

The class \PHPUnit\Framework\Attributes\CoversMethod does not exist at this point.

The expected behavior would be that in version PHPunt 10 the class CoversMethod is excluded.

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