Zend_Test: No default module defined for this application

ぐ巨炮叔叔 提交于 2020-01-02 06:59:26

问题


UPDATE 23 Dec

I had the problem where Zend Framework complains about "No default module defined for this application". I didn't use Modules and the main app works fine.

I finally solved the problem with the help from weierophinney.net

Your bootstrap needs to minimally set the controller directory -- do a call to $this->frontController->addControllerDirectory(...) in your appBootstrap() method. I didn't in my example, as my Initialization plugin does that sort of thing for me.

The problem is solved by adding the below to setUp()

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

But now, I have afew other questions:

1. Why does that value not get initialized by application.ini?

In application.ini, I have

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

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

2. I tried setting the controllerDirectory in bootstrap.php of my unit test, but it does not work

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

The only way that works is using setUp(). Why is that?

END UPDATE 23 Dec


I am getting the above error when unit testing my controller plugins. I am not using any modules. in my bootstrap.php for unit testing, I even tried adding

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

But it still does not work. Anyways my bootstrap.php looks like this

UPDATE: the error looks something like

There were 2 errors:

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

UPDATE

I tried adding

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

then 1 part works.

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');
}

回答1:


The solution it seems is to have this is setUp().

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

Tho I am still looking for answers to my questions posted in the update

1. Why does that value not get initialized by application.ini?

In application.ini, I have

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

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

2. I tried setting the controllerDirectory in bootstrap.php of my unit test, but it does not work

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

. '/controllers');

The only way that works is using setUp(). Why is that?




回答2:


I had the same error, but this did not solve the error at all. Neither in the setUp() method nor in a plugin. But setting the bootstrap resource solved it although it is normaly set by my application. In my case the following worked:

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


来源:https://stackoverflow.com/questions/4507165/zend-test-no-default-module-defined-for-this-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!