Zend框架单元测试在assertResponseCode(200)上失败 [英] Zend Framework Unit Test fails on assertResponseCode(200)

查看:92
本文介绍了Zend框架单元测试在assertResponseCode(200)上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Zend Framework应用程序上运行一些单元测试.我无法理解的是,以下测试失败:

I am running some unit test on my Zend Framework application. What I cant understand is that the following test fails:

public function testCreateFaqItem()
{
    $this->LoginUser();
    $this->dispatch('/faq/admin-faq/create');
    var_dump($this->getResponse());
    $this->assertResponseCode(200);
    $this->assertQueryContentContains('h1', 'Create');
    $this->assertController('admin-faq');
    $this->assertAction('edit');
}

如果在assertResponseCode(200)上失败,则当我删除assertResponseCode(200)时,测试通过.任何帮助将不胜感激.

it fails if on assertResponseCode(200), when i remove the assertResponseCode(200), the test passes. Any help will be much appreciated.

-编辑-

响应对象转储:

object(Zend_Controller_Response_HttpTestCase)#1130 (8) {
  ["_body":protected]=>
  array(1) {
    ["default"]=>
    string(0) ""
  }
  ["_exceptions":protected]=>
  array(0) {
  }
  ["_headers":protected]=>
  array(1) {
    [0]=>
    array(3) {
      ["name"]=>
      string(8) "Location"
      ["value"]=>
      string(13) "/user/profile"
      ["replace"]=>
      bool(true)
    }
  }
  ["_headersRaw":protected]=>
  array(0) {
  }
  ["_httpResponseCode":protected]=>
  int(302)
  ["_isRedirect":protected]=>
  bool(true)
  ["_renderExceptions":protected]=>
  bool(false)
  ["headersSentThrowsException"]=>
  bool(true)
}

谢谢

推荐答案

要解决登录用户并仍然测试响应代码200的问题,我插入了$ this-> resetResponse();.登录用户后.

To fix the problem of logging in the user and still testing for the response code 200, i inserted $this->resetResponse(); after logging in the user.

public function testCreateFaqItem()
    {
        $this->LoginUser();
        $this->resetResponse();
        $this->dispatch('/faq/admin-faq/create');
        $this->assertResponseCode(200);
        $this->assertQueryContentContains('h1', 'Create');
        $this->assertController('admin-faq');
        $this->assertAction('create');
    }

这篇关于Zend框架单元测试在assertResponseCode(200)上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆