簡體   English   中英

Zend_Test:沒有為此應用程序定義的默認模塊

[英]Zend_Test: No default module defined for this application

更新12月23日

我遇到了Zend Framework抱怨“沒有為此應用程序定義默認模塊”的問題。 我沒有使用模塊,主應用程序工作正常。

我終於在weierophinney.net的幫助下解決了這個問題

你的bootstrap需要最低限度地設置控制器目錄 - 在你的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看起來像這樣

更新 :錯誤看起來像

有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

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');
}

似乎解決方案是使用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 

'/控制器');

唯一有效的方法是使用setUp() 這是為什么?

我有同樣的錯誤,但這根本沒有解決錯誤。 既不在setUp()方法也不在插件中。 但是設置引導資源解決了它,盡管它是由我的應用程序正常設置的。 在我的情況下,以下工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM