English 中文(简体)
Zend_Controller_Response_Exception: • 不能派遣负责人;
原标题:Zend_Controller_Response_Exception: Cannot send headers;

在对冻结申请进行所有测试时,这一行文如下:

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_Http.Case。 <代码> Zend_Controller_Response_Http 确实没有派头脑或生产任何东西,而是放弃了一种例外,因为它没有注意产出已经交付。

简单地将以下方法添加到上述类别中。

public function setResp(Zend_Controller_Response_Http $resp) {
    $this->_response = $resp;
}

创建新的<代码>Zend_Controller_Response_Http TestCase,并将之通过setResp(>。 这将使你能够证实正确的头盔与产出是“的”。

问题回答

在我的案件中,我有习惯要求和反应物体:My_Controller_Request_RestMy_Controller_Response_Rest

我已为此设立了一个新的<代码>My_Controller_Request_Rest TestCase和My_Controller_Response_Rest TestCase,其中分别延伸了Zend_Controller_Request_Http TestCase

David Harkness建议实际解决这一问题。 唯一一件事是,贵方的物体必须扩大与每一类产品对应的Http.Case类。

你需要为每个物体建立设计机构,因为不允许你直接确定。

I have the following ControllerTestCase code:

<编码>测试/应用/控制器/制冷剂试验Case.php

abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
    /**
     * Application instance.
     * @var Zend_Application
     */
    protected $application;

    /**
     * Setup test suite.
     *
     * @return void
     */
    public function setUp()
    {
        $this->_setupInitializers();
        $this->bootstrap = array(
            $this,
             applicationBootstrap ,
        );
        parent::setUp();

        $this->setRequest(new My_Controller_Request_RestTestCase());
        $this->setResponse(new My_Controller_Response_RestTestCase());
    }
}

我的习俗要求和反应物体有以下签名:

library/My/Controller/Request/Rest.php

class My_Controller_Request_Rest extends Zend_Controller_Request_Http
{
    // Nothing fancy.
}

library/My/Controller/Response/Rest.php

class Bonzai_Controller_Response_Rest extends Zend_Controller_Response_Http
{
    // Nothing fancy either
}

现在,这是我可以推测的,如何避免在<条码>上重复同样的编号:library/My/Controller/Request/Rest.php/library/My/Controller/Request/Rest TestCase.php>。 我在请求/Rest.php和请求/Rest TestCase.php以及回应/Rest.php和回应/Rest TestCase.php一案中,守则是一样的,但都扩大了<代码>Zend_Controller_(RequestResponse)_Http.Case。

我希望我明确表示。 我知道这个职位是老的,但我认为,应该把这个职位扩大到更多的一点。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签