Find the best Rector rule to solve your problem. Searching through 661 rules.

Found 12 rules:

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()
     {
     }
 }

RequiresAnnotationWithValueToAttributeRector

Change Requires annotations with values to attributes

 use PHPUnit\Framework\TestCase;

-/**
- * @requires PHP > 8.4
- * @requires PHPUnit >= 10
- * @requires OS Windows
- * @requires OSFAMILY Darwin
- * @requires function someFunction
- * @requires function \some\className::someMethod
- * @requires extension mysqli
- * @requires extension mysqli >= 8.3.0
- * @requires setting date.timezone Europe/Berlin
- */
-
+#[\PHPUnit\Framework\Attributes\RequiresPhp('> 8.4')]
+#[\PHPUnit\Framework\Attributes\RequiresPhpunit('>= 10')]
+#[\PHPUnit\Framework\Attributes\RequiresOperatingSystem('Windows')]
+#[\PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily('Darwin')]
+#[\PHPUnit\Framework\Attributes\RequiresFunction('someFunction')]
+#[\PHPUnit\Framework\Attributes\RequiresMethod(\some\className::class, 'someMethod')]
+#[\PHPUnit\Framework\Attributes\RequiresPhpExtension('mysqli')]
+#[\PHPUnit\Framework\Attributes\RequiresPhpExtension('mysqli', '>= 8.3.0')]
+#[\PHPUnit\Framework\Attributes\RequiresSetting('date.timezone', 'Europe/Berlin')]
 final class SomeTest extends TestCase
 {
-    /**
-     * @requires PHP > 8.4
-     * @requires PHPUnit >= 10
-     * @requires OS Windows
-     * @requires OSFAMILY Darwin
-     * @requires function someFunction
-     * @requires function \some\className::someMethod
-     * @requires extension mysqli
-     * @requires extension mysqli >= 8.3.0
-     * @requires setting date.timezone Europe/Berlin
-     */
+
+    #[\PHPUnit\Framework\Attributes\RequiresPhp('> 8.4')]
+    #[\PHPUnit\Framework\Attributes\RequiresPhpunit('>= 10')]
+    #[\PHPUnit\Framework\Attributes\RequiresOperatingSystem('Windows')]
+    #[\PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily('Darwin')]
+    #[\PHPUnit\Framework\Attributes\RequiresFunction('someFunction')]
+    #[\PHPUnit\Framework\Attributes\RequiresMethod(\some\className::class, 'someMethod')]
+    #[\PHPUnit\Framework\Attributes\RequiresPhpExtension('mysqli')]
+    #[\PHPUnit\Framework\Attributes\RequiresPhpExtension('mysqli', '>= 8.3.0')]
+    #[\PHPUnit\Framework\Attributes\RequiresSetting('date.timezone', 'Europe/Berlin')]
     public function test()
     {
     }
 }

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();
     }
 }

PropertyExistsWithoutAssertRector

Replace deleted PHPUnit methods: assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists()

-$this->assertClassHasStaticAttribute("Class", "property");
-$this->classHasStaticAttribute("Class", "property");
-$this->assertClassNotHasStaticAttribute("Class", "property");
+$this->assertTrue(property_exists("Class", "property"));
+$this->assertTrue(property_exists("Class", "property"));
+$this->assertFalse(property_exists("Class", "property"));

WithConsecutiveRector

Refactor deprecated withConsecutive() to willReturnCallback() structure

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function run()
     {
-        $this->personServiceMock->expects($this->exactly(2))
+        $matcher = $this->exactly(2);
+
+        $this->personServiceMock->expects($matcher)
             ->method('prepare')
-            ->withConsecutive(
-                [1, 2],
-                [3, 4],
-            );
+            ->willReturnCallback(function (...$parameters) use ($matcher) {
+                if ($matcher->numberOfInvocations() === 1) {
+                    self::assertEquals([1, 2], $parameters);
+                }
+
+                if ($matcher->numberOfInvocations() === 2) {
+                    self::assertEquals([3, 4], $parameters),
+                };
+            });
     }
 }

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];
     }
 }