使用PHPUnit进行ZendFramework测试无法获得getResponse

时间:2012-07-24 09:17:12

标签: zend-framework phpunit

我有这个测试代码生成Ajax请求,我需要测试响应是有效的JSON,但我无法得到响应。我正在使用PHPUnit 3.5.15和ZendFramework 1.11.11

class ClienteControllerTest extends ControllerTestCase
{

    public function testIndexAjaxAction()
    {
        $this->login();

        $this->resetRequest()->resetResponse();

        $this->dispatch("/cliente/ajax/?sEcho=2&iColumns=7....");

        $this->assertNotController('error');
        $this->assertNotAction('error');
        $this->assertController('cliente');
        $this->assertAction('ajax');

        $this->assertNotRedirect();

        $this->assertResponseCode(200, 'Ajax index fallita');

        //$this->assertNotNull(json_decode($this->getResponse()->getBody()));
        //$this->getResponse()->outputBody();

    }

我试图设置死(print_r($ this-> getResponse))然后我得到了

Zend_Controller_Response_HttpTestCase Ob
(
    [_body:protected] => Array
        (
        )

    [_exceptions:protected] => Array
        (
        )

    [_headers:protected] => Array
        (
        )

    [_headersRaw:protected] => Array
        (
        )

    [_httpResponseCode:protected] => 200
    [_isRedirect:protected] =>
    [_renderExceptions:protected] =>
    [headersSentThrowsException] => 1
)
1

如何在发送()后获得响应?

0 个答案:

没有答案