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

Found 3 rules:

AllowMockObjectsForDataProviderRector

Add #[AllowMockObjectsWithoutExpectations] attribute to PHPUnit test classes that have methods with data providers and mock objects without expectations

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

+#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
 final class SomeClass extends TestCase
 {
     #[DataProvider('someDataProvider')]
     public function test()
     {
         $someMock = $this->createMock(\stdClass::class);
         $someMock->expects('method')->willReturn(true);
     }

     public static function someDataProvider(): iterable
     {
         yield [1];
         yield [2];
         yield [3];
     }
 }

AllowMockObjectsWhereParentClassRector

Add #[AllowMockObjectsWithoutExpectations] attribute to PHPUnit test classes with a 3rd party test case, that provides any mocks

 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

+#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
 final class SomeTest extends ConstraintValidatorTestCase
 {
 }

AllowMockObjectsWithoutExpectationsAttributeRector

Add #[AllowMockObjectsWithoutExpectations] attribute to PHPUnit test classes with mock properties used in multiple methods but one, to avoid irrelevant notices in tests run

 use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
+
+#[AllowMockObjectsWithoutExpectations]
 final class SomeTest extends TestCase
 {
     private \PHPUnit\Framework\MockObject\MockObject $someServiceMock;

     protected function setUp(): void
     {
         $this->someServiceMock = $this->createMock(SomeService::class);
     }

     public function testOne(): void
     {
-        // use $this->someServiceMock
+        $this->someServiceMock->expects($this->once())
+            ->method('someMethod')
+            ->willReturn('someValue');
     }

     public function testTwo(): void
     {
-        // use $this->someServiceMock
+        $this->someServiceMock->expects($this->once())
+            ->method('someMethod')
+            ->willReturn('anotherValue');
     }
 }