Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.10.5
  • Fix Version/s: 1.11.1
  • Component/s: Zend_Test_PHPUnit
  • Labels:
    None

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:

    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:

    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).

Activity

Hide
Richard Tuin added a comment -

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.

Show
Richard Tuin added a comment - 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.
Hide
Richard Tuin added a comment -

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

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

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: