开发者

Zend_Test: No default module defined for this application

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 tes开发者_运维问答ting 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');
}


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?


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());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜