This is an old question, but I struggled with it today and could not find a good answer anywhere, so I will continue and publish what I did to solve this problem. The answer is actually very simple.
Direct the dispatch to an action that will throw exceptions.
My application throws an error when receiving a request to the JSON endpoint, so I used one of them to verify this.
public function testErrorAction500() {
$this->dispatch('/my-json-controller/json-end-point');
$body = $this->getResponse()->getBody();
$this->assertResponseCode('500');
$this->assertContains('Application error',$body);
}
, , , unit test.
public function errorAction() {
throw new Exception('You should not be here');
}
:
public function testErrorAction500() {
$this->dispatch('/my-error-controller/error');
$body = $this->getResponse()->getBody();
$this->assertResponseCode('500');
$this->assertContains('Application error',$body);
}