Issues

ZF-10374: Zend_Controller_Response::setRawHeader() is untestable with Zend_Test_PHPUnit_ControllerTestCase

Issue Type: Bug Created: 2010-08-24T06:47:33.000+0000 Last Updated: 2012-11-06T19:16:33.000+0000 Status: Open Fix version(s): Reporter: Till Klampaeckel (till) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

  • Zend_Test_PHPUnit
  • zf-crteam-review

Related issues: Attachments:

Description

I'm using Zend_Controller_Response::setRawHeader() in one of my actions:

<pre class="highlight">
$this->getResponse()->setRawHeader('HTTP/1.1 300 Multiple Choices');

In my test case (Zend_Test_PHPUnit_ControllerTestCase), I'm using the following assertion:

<pre class="highlight">
$this->assertResponseCode(300);

This however does not work, I dumped Zend_Controller_Response_HttpTestCase and noticed the following:

<pre class="highlight">
   '_headersRaw' => 
  array (
    0 => 'HTTP/1.1 300 Multiple Choices',
  ),
   '_httpResponseCode' => 200,
   '_isRedirect' => false,
   '_renderExceptions' => false,
   'headersSentThrowsException' => true,
))

So the assertion finds 200.

When I curl my action (curl -I http://example.org/controller/action I receive 300 as well. So it seems to work indeed. However, I'm trying to avoid HTTP calls here.

The quickfix is the following:

<pre class="highlight">
$this->getResponse()->setRawHeader('HTTP/1.1 300 Multiple Choices');
$this->getResponse()->setHttpResponseCode(300);

Comments

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T02:40:42.000+0000

Zend_Controller_Response_Http exhibits same behavior. Is this an issue which should be fixed in ZF1? Or is it sufficient to update the manual to note that the HTTP status code cannot be set using setRawHeader alone?

Posted by Till Klampaeckel (till) on 2012-05-12T22:10:03.000+0000

I don't know – IMHO or ideally this would be fixed so setRawHeader() parses the code and end of story. I don't like writing code specific for tests.

I've almost made my peace with Zend_Test since it requires an older version of PHPUnit due to PHPUnit's constant BC breaks. It's a huge inconvenience for development since you have to maintain two versions of PHPUnit and developers need to use it anyway and running tests manually is already a problem and maintaining two setups blows.

Maybe I find some time to update Zend_Test or write a ZendX_Test? Would that be still taken into the tree if I did?

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts