Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
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).
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.