【发布时间】:2012-02-09 23:55:58
【问题描述】:
12 月 23 日更新
我遇到了 Zend Framework 抱怨“没有为此应用程序定义默认模块”的问题。我没有使用模块,主应用程序运行良好。
在weierophinney.net的帮助下终于解决了问题
您的引导程序需要最低限度地设置控制器目录——在您的
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
更新:错误看起来像
有 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');
}
【问题讨论】:
-
能否请您发布错误消息
-
@tawfekov,我更新了帖子
-
尝试做:var_dump($this->getResponse->getBody());我认为错误控制器已被解雇,并会告诉你出了什么问题。
-
@ArneRie,我得到了
Call to undefined method Zend_Controller_Request_HttpTestCase::getBody() -
第一次测试尝试 ($this->assertRedirect('/auth/login');)
标签: unit-testing zend-framework phpunit zend-test