Laravel-Testing-Decoded icon indicating copy to clipboard operation
Laravel-Testing-Decoded copied to clipboard

Mocking Events p134 NoMatchingExpectationException: No matching handler

Open jrohlandt opened this issue 10 years ago • 0 comments

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');

}

jrohlandt avatar Nov 06 '14 09:11 jrohlandt