Zend_Test:没有为此应用程序定义默认模块

发布于 2024-10-08 10:51:08 字数 3871 浏览 7 评论 0原文

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 your appBootstrap() 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2024-10-15 10:51:08

解决方案似乎是使用setUp()

$this->getFrontController()->setControllerDirectory(APPLICATION_PATH . '/controllers');

不过,我仍在寻找更新中发布的问题的答案

<强>1。为什么该值没有被 application.ini 初始化?

application.ini中,我有

<前><代码>[生产]
resources.frontController.controllerDirectory = APPLICATION_PATH“/controllers”

[测试:生产]
// 没有改变任何有关模块或控制器的内容

<强>2。我尝试在中设置 controllerDirectory
我的单元测试的 bootstrap.php ,但是
它不起作用

$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(APPLICATION_PATH)

。 '/控制器');

唯一有效的方法是使用
setUp()。这是为什么?

The solution it seems is to have this is setUp().

$this->getFrontController()->setControllerDirectory(APPLICATION_PATH . '/controllers');

Tho I am still looking for answers to my questions posted in the update

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?

世态炎凉 2024-10-15 10:51:08

我有同样的错误,但这根本没有解决错误。既不在 setUp() 方法中,也不在插件中。但是设置引导资源解决了这个问题,尽管它通常是由我的应用程序设置的。就我而言,以下方法有效:

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

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:

if($this->getFrontController()->getParam('bootstrap') === null) {
    $this->getFrontController()->setParam('bootstrap', $app->getBootstrap());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文