Closed f-albert closed 2 months ago
There is also option to use willReturnMap()
that handles some simpler cases.
There is also option to use
willReturnMap()
that handles some simpler cases.
I don't think so:
withConsecutive
checks if the parameter of a call matches the expected ones. If one parameter is wrong, the test will fail.
willReturnMap
only chooses the right return value based on the parameters. if no parameter list matches the call parameters, the return value will be null
Is it possible to remove this rule first so that other projects do not have the same problem? The PR still needs some time.
implemented at https://github.com/rectorphp/rector-phpunit/pull/313
The implementation of
WithConsecutiveRector
seems to be incorrect. Before:->withConsecutive( [1, 2], [3, 4] );
After:->willReturnCallback(function () use ($matcher) { return match ($matcher->numberOfInvocations()) { 1 => [1, 2], 2 => [3, 4] };
The function
withConsecutive
checks if a function is called with specific parameter. The replacement functionwillReturnCallback
only gets a function which determines the return value but doesn't checks the parameter. Furthermore the function returns the parameter.I will create a PR with a (hopefully correct) solution.