Zend_Test - 在 PHPUnit 的控制器插件中设置重定向
我一直在尝试使用 PHPUnit 来测试应用程序。我一切正常,但无法测试重定向。
我的重定向发生在 Acl 控制器插件内,而不是控制器中的操作内。
我已将它们更改为使用建议的格式
$r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$r->gotoSimple("index", "index", "default");
但这在测试中失败了,响应正文为空,并且出现类似的错误
Zend_Dom_Exception: Cannot query; no document registered
如果我随后更改测试,以便调度方法不会导致 gotoSimple() 被调用然后测试正确运行。
我应该如何在我的应用程序中进行重定向,以便它与 Zend_Test
的响应对象一起正确运行?
Zend 文档用大约两行内容介绍了这一点,我已经尝试过但失败了。
谢谢。
I have been trying to use PHPUnit to test an application. I have it all working, but cannot test redirects.
My redirects are occurring inside an Acl Controller Plugin, not inside an Action in a Controller.
I have changed them to use the suggested format of
$r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$r->gotoSimple("index", "index", "default");
But this fails in the tests, the response body is empty and I get errors like
Zend_Dom_Exception: Cannot query; no document registered
If I then change the test so that the dispatch method does not result in gotoSimple()
being called then the test runs correctly.
How am I supposed to do a redirect in my application so that it runs correctly with Zend_Test
's response object?
The Zend docs cover this in about two lines, which I have tried and it fails.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要测试重定向是否发生,您需要
在运行
$this->dispatch();
之后添加您无法查询响应正文,因为在重定向的情况下它是空的(这就是您的异常来自的地方).
您可以随时检查响应的实际情况
To test that redirect has occurred, you need to add
after running
$this->dispatch();
You cannot query the response body, since it's empty in case of redirect (that's where your exception comes from).
You can always check what the response actually looks like with
确保您的操作在重定向后返回任何内容,因为 Zend_Test_PHPUnit 禁用重定向,所以重定向后的代码也会执行。
或者
要测试重定向本身,您可以使用
assertRedirect*
断言。阅读上面的手册,因为有关于动作钩子的重要注释。
Make sure, your actions return anything after redirections, because Zend_Test_PHPUnit disables redirects, so the code after redirect is executed as well.
or
To test the redirect itself, you may use
assertRedirect*
assertions.Read the above manual, because there are important notes about action hooks.