Zend_Test-在Controller插件中为PHPUnit设置重定向 [英] Zend_Test - Setting redirect in Controller Plugin for PHPUnit

查看:83
本文介绍了Zend_Test-在Controller插件中为PHPUnit设置重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用PHPUnit测试应用程序.我已经完成所有工作,但无法测试重定向.

I have been trying to use PHPUnit to test an application. I have it all working, but cannot test redirects.

我的重定向发生在Acl控制器插件内部,而不是在Controller的操作内部.

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

如果我随后更改测试,以使分发方法不会导致调用gotoSimple(),则测试将正确运行.

If I then change the test so that the dispatch method does not result in gotoSimple() being called then the test runs correctly.

我应该如何在应用程序中进行重定向,以使其与Zend_Test的响应对象一起正常运行?

How am I supposed to do a redirect in my application so that it runs correctly with Zend_Test's response object?

Zend文档涵盖了大约两行,这是我尝试过的,但失败了.

The Zend docs cover this in about two lines, which I have tried and it fails.

谢谢.

推荐答案

要测试是否发生了重定向,您需要添加

To test that redirect has occurred, you need to add

$this->assertRedirectTo( 'index' );

运行$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

print_r( $this->getResponse() );

这篇关于Zend_Test-在Controller插件中为PHPUnit设置重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆