Is it possible to test Exceptions with Laravel resource controllers? Every time I try to do the following:
/**
* @expectedException Exception
* @expectedExceptionMessage Just testing this out
*/
public function testMyPost() {
$response = $this->call('POST', '/api/myapi/', array('testing' => 1));
}
I get:
Failed asserting that exception of type "Exception" is thrown.
I've tried this with \Exception and Exception.
In my resource controller I have:
public function store() {
throw new \Exception('Just for testing!');
}
Does anyone has any idea of I can test Exceptions? I've also tried using:
$this->setExpectedException('InvalidArgumentException');
@expectedException \\Exception?try-catchand get the exact type of exception withget_class($e)? Presumably it's$this->call()what throws an exception, and your original exception is handled by something else.$response = $this->action('POST', 'APIController@store');, nothing seems to be thrown.POSTwithcurland see what is actually returned to you?