JeffreyWay / Laravel-Testing-Decoded

This project is exclusively for reporting typos and errors in the book, "Laravel Testing Decoded."
34 stars 10 forks source link

Mocking Events p134 NoMatchingExpectationException: No matching handler #110

Open jrohlandt opened 9 years ago

jrohlandt commented 9 years ago

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

}