Closed nicolashohm closed 1 week ago
@f-albert reimplement at https://github.com/rectorphp/rector-phpunit/pull/313, could you check?
Cool I missed that. Now it looks way better. Running rector now, results in this:
$mock = $this->createMock(PersonService::class);
$matcher = $this->exactly(2);
$mock->expects($matcher)
->method('prepare')->willReturnCallback(function ($parameters) use ($matcher) : void {
match ($matcher->getInvocationCount()) {
1 => $this->assertEquals([1, 2], $parameters),
2 => $this->assertEquals([3, 4], $parameters),
};
});
$mock->prepare(9, 9);
$mock->prepare(9, 9);
Which has only one little issue which is easy to fix:
- ->method('prepare')->willReturnCallback(function ($parameters) use ($matcher) : void {
+ ->method('prepare')->willReturnCallback(function (...$parameters) use ($matcher) : void {
/cc @f-albert could you check if @nicolashohm suggestion above is correct and can you try apply it? Thank you.
Closing as outdated and lack of feedback last 4 months. Thanks for understanding :+1:
This rule is quite a challange :) if you come across a weird case, please submit a test fixture here:
I saw
WithConsecutiveRector
added in #246 to the PHPUnit 10 rule set, and was keen to use it. But unfortunately, it's not working.I took the example from
tests/Rector/StmtsAwareInterface/WithConsecutiveRector/Fixture/some_class.php.inc
and defined PersonService like this:Original test:
=> Test fails as expected with:
after running the
WithConsecutiveRector
:=> Test is successful even though it shouldn't cause 9 is not equals to the expected value.
the result I get from the rector is already different from what's in the documentation. So I also checked if it would work with the result the documentation provides:
=> Test is successful again, even though it still shouldn't.
Let me know if I missed something. Otherwise, I've unfortunately no idea how to fix this rector.