【发布时间】:2012-06-16 03:13:42
【问题描述】:
我是 100% 代码覆盖率的粉丝,但我不知道如何在 Zend 框架中测试 ErrorController。
测试404Action和errorAction是没问题的:
public function testDispatchErrorAction()
{
$this->dispatch('/error/error');
$this->assertResponseCode(200);
$this->assertController('error');
$this->assertAction('error');
}
public function testDispatch404()
{
$this->dispatch('/error/errorxxxxx');
$this->assertResponseCode(404);
$this->assertController('error');
$this->assertAction('error');
}
但是如何测试应用程序错误(500)? 也许我需要这样的东西?
public function testDispatch500()
{
throw new Exception('test');
$this->dispatch('/error/error');
$this->assertResponseCode(500);
$this->assertController('error');
$this->assertAction('error');
}
【问题讨论】: