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


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() {

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

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