In PHPUnit how can I test if a method is never called with certain arguments? I mean that it can be called with any other arguments even multiple times but never with a certain one.
Looks like it's not possible using the standard way so you can use a callback for specifying the return value, and check the arguments there (bit tricky but seems to work):
$mock = $thi->getMockBuilder('MyClass')->getMock();
$mock->expects($this->any())
->method('myMethod')
->willReturnCallback(function() {
$args = func_get_args();
$disallowedArgs = [1, 'abc'];
$this->assertNotEquals($disallowedArgs, $args);
})
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With