在 Zend Redirector 操作助手中使用 set redirectUrl 方法
我正在 SimpleTest 中对 Zend_Controller_Action 的一些扩展进行单元测试。我希望能够使用 Redirector 操作助手的 set 方法设置重定向 url,然后使用 Redirector 的 redirectAndExit() 方法在稍后的过程中实际重定向。这个过程似乎没有像我通过阅读文档并查看操作控制器、重定向器和响应类中的代码所期望的那样工作。
这是我编写的一个 UnitTestCase 方法:
public function testSetGoToUrl() {
$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();
$controller = new App_Zend_Controller_Action($request, $response, array());
$controller->getHelper('redirector')->setGoToUrl('/');
}
App_Zend_Controller_Action 类只是抽象类 Zend_Controller_Action 的具体扩展。我在这里所做的只是实例化控制器并设置重定向 URL。正如预期的那样,SimpleTest 报告器首先发送标头。但是这个测试方法会生成“标头已发送”异常,我不明白为什么。我不知道在这种情况下调用了任何 run() 或dispatch() 方法。
什么发送第二组标头?
I'm unit testing some extensions of Zend_Controller_Action in SimpleTest. I want to be able to set a redirect url using the set methods of the Redirector action helper, and then use Redirector's redirectAndExit() method to actually redirect later in the process. This process doesn't seem to be working as I expected from reading the documentation and looking at the code in the action controller, redirector and response classes.
Here's a UnitTestCase method I wrote:
public function testSetGoToUrl() {
$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();
$controller = new App_Zend_Controller_Action($request, $response, array());
$controller->getHelper('redirector')->setGoToUrl('/');
}
The App_Zend_Controller_Action class is merely a concrete extension of the abstract class Zend_Controller_Action. All I'm doing here is instantiating the controller and setting the redirection url. The SimpleTest reporter is sending the headers first, as expected. But this test method generates a "headers sent" exception and I don't understand why. I'm not aware of any run() or dispatch() methods being called in this situation.
What's sending the second set of headers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
测试时您应该使用
Zend_Controller_Response_HttpTestCase
和Zend_Controller_Request_HttpTestCase
。Zend_Controller_Response_HttpTestCase::sendHeaders()
返回将发送的所有标头的数组,而不是执行真正的header()
语句。这些也用在
Zend_Test_PHPUnit_ControllerTestCase
中。While testing you should use
Zend_Controller_Response_HttpTestCase
andZend_Controller_Request_HttpTestCase
.Zend_Controller_Response_HttpTestCase::sendHeaders()
returns an array of all headers that would be sent instead of executing realheader()
statements.These are also used in
Zend_Test_PHPUnit_ControllerTestCase
.