PHPUnit Zend框架控制器测试 - 无法断言上次使用的控制器<"错误"> - 显示错误

Jam*_*ore 4 phpunit zend-framework

我们目前正在对zend框架控制器进行单元测试.

(我已经抽象了一下这个代码示例,但想法是一样的....)

我们很高兴设法使测试失败,并显示错误消息

Failed asserting last controller used <"error"> ....

通过测试:

$this->dispatch('/controller/action/param');
$this->assertController('controller');
$this->assertAction('action');
Run Code Online (Sandbox Code Playgroud)

所以在这个例子中,我如何得到真正的错误消息到泡泡到PHPUnit,即如果控制器中有错误,我想知道它而不是调用错误控制器.

如果我resources.frontController.params.noErrorHandler = 1在application.ini中设置,即使出现错误,测试也会通过,因为控制器和操作仍然会发生,但只输出任何内容(我知道我可以在输出中查找断言,但这不是重点 - 我想要原始错误).

我试过打开了

convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true" 
Run Code Online (Sandbox Code Playgroud)

在phpunit.xml中,也没有快乐.

任何指针都将非常感激.

我希望所有这一切都有意义!?

非常感谢.

Cia*_*lty 5

不幸的是,Zend_Test_PHPUnit_ControllerTestCase在调度期间显式覆盖了一些前控制器选项.相关的代码位在这里:

$controller = $this->getFrontController();
$this->frontController
     ->setRequest($request)
     ->setResponse($this->getResponse())
     ->throwExceptions(false)
     ->returnResponse(false);
Run Code Online (Sandbox Code Playgroud)

因为这是在dispatch()内完成的,所以你绝对没有机会改变选项.

我使用的一个解决方案是创建我自己的基础ControllerTestCase,它扩展Zend,并从Zend对象复制整个dispatch()函数,然后更改那一行.

它很乱,但它有效.你可以做一个更复杂的版本,从配置等读取东西.