Zend Framework中的UnitTest错误控制器

opH*_*AME 5 phpunit zend-framework

我是100%代码覆盖率的粉丝,但我不知道如何在Zend Framework中测试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');
    }
Run Code Online (Sandbox Code Playgroud)

但是如何测试应用程序错误(500)?也许我需要这样的东西?

public function testDispatch500()
{
    throw new Exception('test');

    $this->dispatch('/error/error');
    $this->assertResponseCode(500);
    $this->assertController('error');
    $this->assertAction('error');

}
Run Code Online (Sandbox Code Playgroud)

sal*_*igy 0

好吧,我对这个主题不太熟悉,但我会使用自定义 ErrorHandler 插件来操纵此行为(扩展原始版本,并假装抛出异常)。也许可以只注册一次测试。