Refactor deprecated withConsecutive() to willReturnCallback() structure
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function run()
{
- $this->personServiceMock->expects($this->exactly(2))
+ $matcher = $this->exactly(2);
+
+ $this->personServiceMock->expects($matcher)
->method('prepare')
- ->withConsecutive(
- [1, 2],
- [3, 4],
- );
+ ->willReturnCallback(function (...$parameters) use ($matcher) {
+ if ($matcher->numberOfInvocations() === 1) {
+ self::assertEquals([1, 2], $parameters);
+ }
+
+ if ($matcher->numberOfInvocations() === 2) {
+ self::assertEquals([3, 4], $parameters),
+ };
+ });
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector;
return RectorConfig::configure()
->withRules([
WithConsecutiveRector::class,
]);