Add a MockObject intersection @var docblock with the mocked class to a native MockObject property
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject&\SomeService
+ */
private \PHPUnit\Framework\MockObject\MockObject $someServiceMock;
protected function setUp(): void
{
$this->someServiceMock = $this->createMock(SomeService::class);
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddIntersectionVarToMockObjectPropertyRector;
return RectorConfig::configure()
->withRules([
AddIntersectionVarToMockObjectPropertyRector::class,
]);