Zend_Test:没有为此应用程序定义默认模块
12 月 23 日更新
我遇到了 Zend Framework 抱怨“没有为此应用程序定义默认模块”的问题。我没有使用模块,主应用程序工作正常。
我终于在 weierophinney 的帮助下解决了这个问题。网
您的引导程序需要至少设置控制器目录 - 在
appBootstrap()
中调用$this->frontController->addControllerDirectory(...)
代码>方法。在我的示例中,我没有这样做,因为我的初始化插件为我做了类似的事情。
通过将以下内容添加到 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.我尝试在单元测试的 bootstrap.php
中设置 controllerDirectory
,但它不起作用
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(APPLICATION_PATH . '/controllers');
唯一有效的方法是使用 setUp()
。这是为什么?
12 月 23 日结束更新
在对我的控制器插件进行单元测试时,我收到上述错误。我没有使用任何模块。在我的 bootstrap.php 中进行单元测试,我什至尝试添加
$front = Zend_Controller_Front::getInstance();
$front->setDefaultModule('default');
但它仍然不起作用。无论如何,我的 bootstrap.php 看起来像 this
更新:错误看起来像
There were 2 error:
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
我尝试添加
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');
}
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');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案似乎是使用
setUp()
。不过,我仍在寻找更新中发布的问题的答案
The solution it seems is to have this is
setUp()
.Tho I am still looking for answers to my questions posted in the update
我有同样的错误,但这根本没有解决错误。既不在 setUp() 方法中,也不在插件中。但是设置引导资源解决了这个问题,尽管它通常是由我的应用程序设置的。就我而言,以下方法有效:
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: