Zend_Test: No default module defined for this application
Posted
by
jiewmeng
on Stack Overflow
See other posts from Stack Overflow
or by jiewmeng
Published on 2010-12-22T07:49:10Z
Indexed on
2010/12/23
6:54 UTC
Read the original article
Hit count: 330
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 yourappBootstrap()
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');
}
© Stack Overflow or respective owner