zend_test:无针对此应用程序定义的默认模块
-
12-10-2019 - |
题
更新12月23日
我遇到了一个问题,Zend Framework抱怨“未针对此应用程序定义默认模块”。我没有使用模块,主应用程序正常运行。
我终于在我的帮助下解决了问题 weierophinney.net
您的bootstrap需要最少设置控制器目录 - 呼叫
$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()
. 。这是为什么?
结束更新12月23日
单元测试控制器插件时,我会遇到上述错误。我不使用任何模块。在我的Bootstrap.php进行单元测试中,我什至尝试添加
$front = Zend_Controller_Front::getInstance();
$front->setDefaultModule('default');
但这仍然行不通。无论如何我的bootstrap.php看起来像 这个
更新: :错误看起来像
有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');
}
解决方案
解决方案似乎是 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()
. 。这是为什么?
其他提示
我有同样的错误,但这根本没有解决错误。在setup()方法中都不是在插件中。但是设置引导资源已解决了它,尽管它是由我的应用程序设置的。就我而言,以下是有效的:
if($this->getFrontController()->getParam('bootstrap') === null) {
$this->getFrontController()->setParam('bootstrap', $app->getBootstrap());
}