【问题标题】:Zend_Test: No default module defined for this applicationZend_Test:没有为此应用程序定义默认模块
【发布时间】: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


【解决方案1】:

解决方案似乎是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

。 '/控制器');

唯一可行的方法是使用 setUp()。这是为什么呢?

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,但这根本没有解决错误。在 setUp() 方法和插件中都没有。但是设置引导资源解决了它,尽管它通常是由我的应用程序设置的。在我的情况下,以下工作:

    if($this->getFrontController()->getParam('bootstrap') === null) {
        $this->getFrontController()->setParam('bootstrap', $app->getBootstrap());
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 2019-08-21
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      相关资源
      最近更新 更多