Add a MockObject intersection @param docblock with the mocked class, based on the mock passed in the private method call
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test(): void
{
$someService = $this->createMock(SomeService::class);
$this->prepareServiceMock($someService);
}
+ /**
+ * @param \SomeService&\PHPUnit\Framework\MockObject\MockObject $someService
+ */
private function prepareServiceMock(MockObject $someService): void
{
$someService->expects($this->once())
->method('getId');
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddIntersectionParamToMockObjectParamRector;
return RectorConfig::configure()
->withRules([
AddIntersectionParamToMockObjectParamRector::class,
]);