ZF-9899: $this->getRequest()->getHttpHost() returning the ":" character when run through a test
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).
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)