Issues

ZF-9899: $this->getRequest()->getHttpHost() returning the ":" character when run through a test

Issue Type: Bug Created: 2010-05-27T04:14:58.000+0000 Last Updated: 2010-11-20T02:58:46.000+0000 Status: Resolved Fix version(s): - 1.11.1 (30/Nov/10)

Reporter: Doron Gutman (gshockoman) Assignee: Richard Tuin (richardtuin) Tags: - Zend_Test_PHPUnit

Related issues: Attachments: - ZF-9899-rtuin.patch

Description

When running a controller unit test (using the $this->dispatch('/') for example), a call to $this->getRequest()->getHttpHost() in a controller returns the colon sign - ":".

To replicate:

Create the following action in a controller:

<pre class="literal">
    public function colonAction() {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
        $this->getResponse()->setBody($this->getRequest()->getHttpHost());
    }

If you'll go over to that action in a browser, you'll get the appropriate host name.

Now write a test with the following method:

<pre class="literal">
    public function test_colonAction() {
        $this->dispatch('/index/colon');
        self::assertEquals(':', $this->getResponse()->getBody());
    }

Running the test will result in a successful run (which means the getHttpHost method returns a : sign when run in a test).

Comments

Posted by Richard Tuin (richardtuin) on 2010-11-19T15:22:05.000+0000

Although this result is expected as the tests are run from CLI, it is good to clean up the output of this method.

I have attached a patch file which does this, with the associated unit test.

Elaboration on my patch fix: The reason i have chosen to test against SERVER_NAME, instead of php_sapi_name() is that other tests simulating an HTTP request would fail.

Posted by Richard Tuin (richardtuin) on 2010-11-20T02:58:46.000+0000

[SVN:r23414:bittarman] ZF-9899: Merging r23413 to release branch 1.11 (See: http://tinyurl.com/2bhk4cr)

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