加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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);

生成以下错误:

Zend_Controller_Response_Exception: Cannot send headers; headers
already sent in /usr/share/php5/PEAR/PHPUnit/Util/Printer.php,line
173

结果 – 测试失败了

解决方法

这是因为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().这也将允许您验证正确的标题是否与输出一起“发送”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读