phpunittest期间清空$ _controllerDirectory数组(来自Zend_Controller_Dispatcher_Standard)

时间:2010-11-19 16:03:55

标签: php unit-testing zend-framework

我正在尝试使用Zend_Framework(v 1.10.8)运行phpUnitTest(3.5.4)并仍然接收

Zend_Controller_Exception: No default module defined for this application

例如测试类AuthControllerTest,它扩展了Zend_Test_PHPUnit_ControllerTestCase

/**  * @test  */ public function
loginPage() {

  $this->dispatch('/login');
  $this->assertController('auth');
  $this->assertAction('login'); }

调试后,我发现Zend_Controller_Dispatcher_Standard中的变量$ _controllerDirectory为空。通常它包含:

  

array'Default'=>串   'C:\ X \ phpcode \应用/模块\默认\控制器的

我已经定义了路由器

 <loginPage>
     <route>login</route>
     <defaults>
         <module>default</module>
         <controller>auth</controller>
         <action>login</action>
     </defaults>
     <map>
     </map>
     <reverse>login</reverse>
 </loginPage>

和其他FC参数

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.baseUrl = "http://www.fff44.pl:8080/"
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "default"

可能出错?

1 个答案:

答案 0 :(得分:0)

你使用zend_application吗?

我的解决方案:

protected function _setUp ()
{
    // your Zend_Application instance from your own test-bootstrap file
    $application = Zend_Registry::get('application');

    if ($this->bootstrap === null) {
        $this->bootstrap = new Zend_Application (
            $application->getEnvironment(),
            $application->getOptionsFile(),
            $application->getDefaultsFile()
        );
    }

    parent::_setUp();
}