Narrow single-value match willReturnCallback() to with() and willReturn() call
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function run()
{
$matcher = $this->exactly(1);
$this->personServiceMock->expects($matcher)
- ->willReturnCallback(function (...$parameters) use ($matcher) {
- match ($matcher->getInvocationCount()) {
- 1 => $this->assertSame([1], $parameters),
- };
- });
+ ->with(1, $parameters);
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowSingleWillReturnCallbackRector;
return RectorConfig::configure()
->withRules([
NarrowSingleWillReturnCallbackRector::class,
]);