Skip to content

Commit

Permalink
add expects call
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 25, 2024
1 parent b4acf4b commit a49d8fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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->expects($matcher)->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 @@ -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

0 comments on commit a49d8fc

Please sign in to comment.