Php 使用Zend Redirector action helper中的set redirectUrl方法
我正在SimpleTest中对Zend_Controller_操作的一些扩展进行单元测试。我希望能够使用Redirector action helper的set方法设置重定向url,然后使用Redirector的redirectAndExit()方法在稍后的过程中实际重定向。通过阅读文档和查看action controller、redirector和response类中的代码,这个过程似乎没有达到我预期的效果 我写了一个UnitTestCase方法:Php 使用Zend Redirector action helper中的set redirectUrl方法,php,zend-framework,simpletest,Php,Zend Framework,Simpletest,我正在SimpleTest中对Zend_Controller_操作的一些扩展进行单元测试。我希望能够使用Redirector action helper的set方法设置重定向url,然后使用Redirector的redirectAndExit()方法在稍后的过程中实际重定向。通过阅读文档和查看action controller、redirector和response类中的代码,这个过程似乎没有达到我预期的效果 我写了一个UnitTestCase方法: public function test
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 reporter将首先发送标题。但是这个测试方法会生成一个“headers sent”异常,我不明白为什么。我不知道在这种情况下会调用任何run()或dispatch()方法
什么在发送第二组头?在测试时,您应该使用
Zend\u Controller\u Response\u HttpTestCase
和Zend\u Controller\u Request\u HttpTestCase
Zend\u Controller\u Response\u HttpTestCase::sendHeaders()
返回将发送的所有头的数组,而不是执行realheader()
语句
它们也被用于Zend_Test_PHPUnit_ControllerTestCase这是一个好主意,我刚刚知道了发生了什么。没有任何内容尝试发送第二组标头;异常由响应对象的canSendHeaders()方法生成,该方法在响应对象设置重定向时调用。谢谢