Laravel-Testing-Decoded
Laravel-Testing-Decoded copied to clipboard
Mocking Events p134 NoMatchingExpectationException: No matching handler
For those who, like me are brand new to testing and, might end up spending almost an hour trying to figure out why this error (NoMatchingExpectationException: No matching handler) occurs, in this example, the quick answer is to use ->withArgs() instead of ->with(), which I believe cannot accept arrays.
public function testDestroyUser() { Event::shouldReceive('fire') ->once() ->withArgs(['cancellation', Mockery::any()]); // withArgs()
// Perform any other necessary expectations
$this->call('DELETE', '/users/1');
}