Skip to content

phpunit @uses transformed into method level attribute #9178

@staabm

Description

@staabm

Bug Report

Subject Details
Rector version 2.0.8

in my test-suite rector is creating the following diff:

 namespace rocket\tests\unit\lib;

+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\UsesClass;
 use PHPUnit\Framework\TestCase;

 final class RegexFormatsUrlTest extends TestCase
 {
-    /**
-     * @dataProvider provideValidUrls
-     *
-     * @uses \RegexFormats
-     */
+    #[DataProvider('provideValidUrls')]
+    #[UsesClass('\RegexFormats')]
     public function testUrlRegexValid(string $url): void
     {
         self::assertTrue((bool) preg_match('{' . REGEX_URL . '}', $url));
     }
    ----------- end diff -----------

Applied rules:
 * DataProviderAnnotationToAttributeRector
 * PreferPHPUnitSelfCallRector
 * PreferPHPUnitThisCallRector
 * AnnotationToAttributeRector
 * AddParamTypeBasedOnPHPUnitDataProviderRector

the problem here is, that a #UsesClass attribute is created at method level, but it is only valid at class level, see

Image

Minimal PHP Code Causing Issue

unfortunately I am not able to reproduce it in the sandbox

https://getrector.com/demo/771e7c3e-d548-4aae-8b12-c9593e40d507

Expected Behaviour

#UsesClass - similar to e.g. #CoversMethod should move the annotation to class-level even if the phpdoc itself was at method level

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions