Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class CombineWithOnConsecutiveWithoutExcepts extends TestCase
public function test()
{
$matcher = $this->exactly(2);
$this->userServiceMock->method('prepare')->willReturnCallback(function ($parameters) use ($matcher) {
$this->userServiceMock->method('prepare')->expects($matcher)->willReturnCallback(function ($parameters) use ($matcher) {
match ($matcher->numberOfInvocations()) {
1 => self::assertEquals([1, 2], $parameters),
2 => self::assertEquals([3, 4], $parameters),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\PHPUnit\Tests\Rector\StmtsAwareInterface\WithConsecutiveRector\WithConsecutiveRectorTest
* @see \Rector\PHPUnit\Tests\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector\WithConsecutiveRectorTest
*/
final class WithConsecutiveRector extends AbstractRector implements MinPhpVersionInterface
{
Expand Down Expand Up @@ -386,6 +386,16 @@ private function refactorToWillReturnCallback(
)),
];

$hasExpects = $this->findMethodCall($expression, 'expects') instanceof MethodCall;
if ($hasExpects === false) {
/** @var MethodCall $mockMethodCall */
$mockMethodCall = $expression->expr;

$mockMethodCall->var = new MethodCall($mockMethodCall->var, 'expects', [
new Arg(new Variable('matcher')),
]);
}

$matcherAssign = new Assign(new Variable('matcher'), $expectsCall);
return [new Expression($matcherAssign), $expression];
}
Expand Down