PHPUnit version : 11.5.6
Given a class Foo with bar method with variadic params:
class Foo
{
public function bar(int ...$params): void {}
}
I mock a Foo instance in a test and want to assert bar has been called with exactly 2 parameters (not one more).
public function testIsCalledWithTwoParameters()
{
$mock = $this->createMock(Foo::class);
$mock->expects($this->once())
->method('bar')
->with(1, 2);
$mock->bar(1, 2);
}
Problem is: changing call for $mock->bar(1, 2, 3); will not trigger an error.
NB 1: With previous versions of PHPUnit, variadic params were sent to callback as a unique array but it seems it is not longer the case in 11.5.6.