Change $this->createMock() with methods to direct anonymous class
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
- $someMockObject = $this->createMock(SomeClass::class);
-
- $someMockObject->method('someMethod')
- ->willReturn(100);
+ $someMockObject = new class extends SomeClass {
+ public function someMethod()
+ {
+ return 100;
+ }
+ };
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\CreateMockToAnonymousClassRector;
return RectorConfig::configure()
->withRules([
CreateMockToAnonymousClassRector::class,
]);