Zend_Test:没有为此应用程序定义的默认模块

时间:2010-12-22 07:49:11

标签: unit-testing zend-framework phpunit zend-test

12月23日更新

我遇到了Zend Framework抱怨“没有为此应用程序定义默认模块”的问题。我没有使用模块,主应用程序工作正常。

我终于在weierophinney.net

的帮助下解决了这个问题
  

您的引导程序需要最低限度地设置控制器目录 - 在$this->frontController->addControllerDirectory(...)方法中调用appBootstrap()。我没有在我的例子中,因为我的初始化插件为我做了那样的事情。

通过将以下内容添加到setUp()

来解决问题
$this->getFrontController()->setControllerDirectory(APPLICATION_PATH . '/controllers');

但是现在,我还有其他一些问题:

1。为什么application.ini无法初始化该值?

application.ini,我有

[production]
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[testing : production]
// didn't change anything regarding modules nor controllers

2。我尝试在我的单元测试的controllerDirectory中设置bootstrap.php,但它不起作用

$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(APPLICATION_PATH . '/controllers');

唯一可行的方法是使用setUp()。那是为什么?

END更新12月23日


单元测试控制器插件时出现上述错误。我没有使用任何模块。在我的bootstrap.php中进行单元测试,我甚至尝试添加

$front = Zend_Controller_Front::getInstance();
$front->setDefaultModule('default');

但它仍然无效。无论如何,我的bootstrap.php看起来像 this

更新:错误类似于

有2个错误:

1) Application_Controller_Plugin_AclTest::testAccessToUnauthorizedPageRedirectsToLogin
Zend_Controller_Exception: No default module defined for this application

D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:391
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:204
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:244
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Front.php:954
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Test\PHPUnit\ControllerTestCase.php:205
D:\Projects\Tickle\tests\application\controllers\plugins\aclTest.php:6

2) Application_Controller_Plugin_AclTest::testAccessToAllowedPageWorks
Zend_Controller_Exception: No default module defined for this application

D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:391
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:204
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Dispatcher\Standard.php:244
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Controller\Front.php:954
D:\ResourceLibrary\Frameworks\PHPFrameworks\Zend\Test\PHPUnit\ControllerTestCase.php:205
D:\Projects\Tickle\tests\application\controllers\plugins\aclTest.php:16

更新

我尝试添加

public function setUp() {
  $front = Zend_Controller_Front::getInstance();
  $front->setDefaultModule('default');
}

然后1部分工作。

public function testAccessToUnauthorizedPageRedirectsToLogin() { // this fails with exception "Zend_Controller_Exception: No default module defined for this application"
  $this->dispatch('/projects');
  $this->assertController('auth');
  $this->assertAction('login');
}

public function testAccessToAllowedPageWorks() { // this passes
  $auth = Zend_Auth::getInstance();
  $authAdapter = new Application_Auth_Adapter('jiewmeng', 'password');
  $auth->authenticate($authAdapter);

  $this->dispatch('/projects');
  $this->assertController('projects');
  $this->assertAction('index');
}

2 个答案:

答案 0 :(得分:3)

似乎解决方案是setUp()

$this->getFrontController()->setControllerDirectory(APPLICATION_PATH . '/controllers');

我仍然在寻找更新中发布的问题的答案

  

<强> 1。为什么app.ini没有初始化该值?

     

application.ini,我有

[production]
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[testing : production]
// didn't change anything regarding modules nor controllers
     

<强> 2。我尝试设置controllerDirectory   bootstrap.php我的单元测试,但是   它不起作用

$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(APPLICATION_PATH
     

。 '/控制器');

     

唯一可行的方法是使用   setUp()。那是为什么?

答案 1 :(得分:1)

我有同样的错误,但这根本没有解决错误。既不在setUp()方法也不在插件中。但是设置引导资源解决了它,尽管它是由我的应用程序正常设置的。在我的情况下,以下工作:

if($this->getFrontController()->getParam('bootstrap') === null) {
    $this->getFrontController()->setParam('bootstrap', $app->getBootstrap());
}
相关问题