php – Zend_Controller_Response_Exception:无法发送标头;
发布时间:2020-12-13 16:22:37 所属栏目:PHP教程 来源:网络整理
导读:当运行zend应用程序的所有测试时,这一行: protected function _getResp(){ if (is_null($this-_response)) $this-_response = new Zend_Controller_Response_Http(); return $this-_response;}.......$this-_getResp()-setHeader('Content-Type','text/html
当运行zend应用程序的所有测试时,这一行:
protected function _getResp() { if (is_null($this->_response)) $this->_response = new Zend_Controller_Response_Http(); return $this->_response; } ....... $this->_getResp()->setHeader('Content-Type','text/html; charset=utf-8',true); 生成以下错误:
结果 – 测试失败了 解决方法
这是因为PHPUnit在测试运行之前生成输出.您需要在测试用例中注入Zend_Controller_Response_HttpTestCase. Zend_Controller_Response_Http的这个子类实际上并不发送头文件或输出任何内容,并且它不会抛出异常,因为它不关心输出是否已经发送过.
只需将以下方法添加到上面的类中. public function setResp(Zend_Controller_Response_Http $resp) { $this->_response = $resp; } 创建一个新的Zend_Controller_Response_HttpTestCase并将其传递给您正在测试的对象上的setResp().这也将允许您验证正确的标题是否与输出一起“发送”. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |