How to submit url with subdomain to Zend PHPUnit controller test?

I want to test my controller that is running on the subdomain www.username.domain.com

The problem is when I post to ControllerTestCase it throws Zend_Controller_Dispatcher_Exception


routes.php:

$userRouter = new Zend_Controller_Router_Route_Hostname(':user.domain.com'));

$router->addRoute('user', $userRouter->chain(new Zend_Controller_Router_Route('',
                            array('controller' => 'user'))));

      


UserControllerTest:

require_once 'AbstarctControllerTestCase.php';

class UserControllerTest extends AbstarctControllerTestCase
{
    public function setUp()
    {
        $this->cleardb();
        parent::setUp();
    }

    public function testRoute()
    {
        $this->dispatch('www.username.domain.com');
        $this->assertController('user');
    }
}

      


AbstarctControllerTestCase:

abstract class AbstarctControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
    public function setUp()
    {
        $this->bootstrap = array($this, 'appBootstrap');
        parent::setUp();
    }

    public function appBootstrap()
    {
        chdir(dirname(dirname(dirname(dirname(__FILE__)))));
        require 'application/test/controllerunit/routes.php';
        Zend_Session::start();
    }
(...)
}

      

Result:

PHPUnit 3.3.17 by Sebastian Bergmann.

F

Time: 1 second

There was 1 failure:

1) testRoute(UserControllerTest)
Failed asserting last controller used was "user"

      

When I send a normal URI like / login it works well, but the problem is sending URLs with hostnames.

Any ideas? Thanks everyone.

+2


source to share


2 answers


Have you tried setting the $ _SERVER variable in setup?

eg.

$_SERVER['SERVER_NAME'] = 'www.username.domain.com';

      



and then invoke the dispatch as usual.

See - http://php.net/manual/en/reserved.variables.server.php

+2


source


Define $_SERVER['HTTP_HOST']

before calling dispatch()

.



There is already a ticket with the same concern at http://framework.zend.com/issues/browse/ZF-11680

+2


source







All Articles