Find the best Rector rule to solve your problem



Configurable

RenameClassRector

Replaces defined classes by new ones.

 namespace App;

-use SomeOldClass;
+use SomeNewClass;

-function someFunction(SomeOldClass $someOldClass): SomeOldClass
+function someFunction(SomeNewClass $someOldClass): SomeNewClass
 {
-    if ($someOldClass instanceof SomeOldClass) {
-        return new SomeOldClass;
+    if ($someOldClass instanceof SomeNewClass) {
+        return new SomeNewClass;
     }
 }

GetMockBuilderGetMockToCreateMockRector

Remove getMockBuilder() to createMock()

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function test()
     {
-        $applicationMock = $this->getMockBuilder('SomeClass')
-           ->disableOriginalConstructor()
-           ->getMock();
+        $applicationMock = $this->createMock('SomeClass');
     }
 }

DelegateExceptionArgumentsRector

Takes setExpectedException() 2nd and next arguments to own methods in PHPUnit.

 use PHPUnit\Framework\TestCase;

 class SomeTest extends TestCase
 {
     public function test()
     {
-        $this->setExpectedException(SomeException::class, "Message", "CODE");
+        $this->setExpectedException(SomeException::class);
+        $this->expectExceptionMessage('Message');
+        $this->expectExceptionCode('CODE');
     }
 }

ExceptionAnnotationRector

Changes @expectedException annotations to expectException*()` methods

-/**
- * @expectedException Exception
- * @expectedExceptionMessage Message
- */
 public function test()
 {
+    $this->expectException('Exception');
+    $this->expectExceptionMessage('Message');
     // tested code
 }

AddDoesNotPerformAssertionToNonAssertingTestRector

Tests without assertion will have @doesNotPerformAssertion

 use PHPUnit\Framework\TestCase;

 class SomeClass extends TestCase
 {
+    /**
+     * @doesNotPerformAssertions
+     */
     public function test()
     {
         $nothing = 5;
     }
 }