我想测试在子域 www.username.domain.com 上工作的控制器
问题是当我在 ControllerTestCase 调度它抛出 Zend_Controller_Dispatcher_Exception
路线.php:
$userRouter = new Zend_Controller_Router_Route_Hostname(':user.domain.com'));
$router->addRoute('user', $userRouter->chain(new Zend_Controller_Router_Route('',
array('controller' => 'user'))));
用户控制器测试:
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');
}
}
抽象控制器测试用例:
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();
}
(...)
}
结果:
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"
当我发送像 /login 这样的普通 URI 时,它运行良好,但问题是发送带有主机名的 URL。
有任何想法吗?谢谢你们。