Find the best Rector rule to solve your problem



Configurable

AnnotationToAttributeRector

Change annotation to attribute

 use Symfony\Component\Routing\Annotation\Route;

 class SymfonyRoute
 {
-    /**
-     * @Route("/path", name="action") api route
-     */
+    #[Route(path: '/path', name: 'action')] // api route
     public function action()
     {
     }
 }

TicketAnnotationToAttributeRector

Change annotations with value to attribute

 use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\Ticket;

-/**
- * @ticket 123
- */
+#[Ticket('123')]
 final class SomeTest extends TestCase
 {
 }

CoversAnnotationWithValueToAttributeRector

Change covers annotations with value to attribute

 use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\CoversFunction;

-/**
- * @covers SomeClass
- */
+#[CoversClass(SomeClass::class)]
+#[CoversFunction('someFunction')]
 final class SomeTest extends TestCase
 {
-    /**
-     * @covers ::someFunction()
-     */
     public function test()
     {
     }
 }

Configurable

AnnotationWithValueToAttributeRector

Change annotations with value to attribute

 use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\BackupGlobals;

-/**
- * @backupGlobals enabled
- */
+#[BackupGlobals(true)]
 final class SomeTest extends TestCase
 {
 }

DependsAnnotationWithValueToAttributeRector

Change depends annotations with value to attribute

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function testOne() {}

-    /**
-     * @depends testOne
-     */
+    #[\PHPUnit\Framework\Attributes\Depends('testOne')]
     public function testThree(): void
     {
     }
 }

TestWithAnnotationToAttributeRector

Change @testWith() annotation to #[TestWith] attribute

 use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\TestWith;

 final class SomeFixture extends TestCase
 {
-    /**
-     * @testWith ["foo"]
-     *           ["bar"]
-     */
+    #[TestWith(['foo'])]
+    #[TestWith(['bar'])]
     public function test(): void
     {
     }
 }

DataProviderAnnotationToAttributeRector

Change dataProvider annotations to attribute

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
-    /**
-     * @dataProvider someMethod()
-     */
+    #[\PHPUnit\Framework\Attributes\DataProvider('someMethod')]
     public function test(): void
     {
     }
 }

RemoveSetMethodsMethodCallRector

Remove "setMethods()" method as never used, move methods to "addMethods()" if non-existent or @method magic

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function test()
     {
         $someMock = $this->getMockBuilder(SomeClass::class)
-            ->setMethods(['run'])
             ->getMock();
     }
 }

AssertIssetToAssertObjectHasPropertyRector

Change "isset()" property check, to assertObjectHasProperty() method

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function test()
     {
         $object = new stdClass();
-        $this->assertTrue(isset($object->someProperty));
+        $this->assertObjectHasProperty('someProperty', $object);
     }
 }

PublicDataProviderClassMethodRector

Change data provider methods to public

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     /**
      * @dataProvider provideData()
      */
     public function test()
     {
     }

-    protected static function provideData()
+    public static function provideData()
     {
         yield [1];
     }
 }

AddProphecyTraitRector

Add Prophecy trait for method using $this->prophesize()

 use PHPUnit\Framework\TestCase;
+use Prophecy\PhpUnit\ProphecyTrait;

 final class ExampleTest extends TestCase
 {
+    use ProphecyTrait;
+
     public function testOne(): void
     {
         $prophecy = $this->prophesize(\AnInterface::class);
     }
 }

StaticDataProviderClassMethodRector

Change data provider methods to static

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     /**
      * @dataProvider provideData()
      */
     public function test()
     {
     }

-    public function provideData()
+    public static function provideData()
     {
         yield [1];
     }
 }