Zend_Test:Für diese Anwendung ist kein Standardmodul definiert
-
12-10-2019 - |
Frage
UPDATE 23. Dez
Ich hatte das Problem, dass sich Zend Framework über „Für diese Anwendung ist kein Standardmodul definiert“ beschwert.Ich habe keine Module verwendet und die Haupt-App funktioniert einwandfrei.
Ich habe das Problem endlich mit der Hilfe von gelöst weierophinney.net
Ihr Bootstrap muss das Controller-Verzeichnis minimal festlegen – rufen Sie dazu auf
$this->frontController->addControllerDirectory(...)
in deinemappBootstrap()
Methode.In meinem Beispiel habe ich das nicht getan, da mein Initialisierungs-Plugin so etwas für mich erledigt.
Das Problem wird durch Hinzufügen des Folgenden gelöst setUp()
$this->getFrontController()->setControllerDirectory(APPLICATION_PATH . '/controllers');
Aber jetzt habe ich noch ein paar andere Fragen:
1.Warum wird dieser Wert nicht initialisiert? application.ini
?
In application.ini
, Ich habe
[production]
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
[testing : production]
// didn't change anything regarding modules nor controllers
2.Ich habe versucht, das einzustellen controllerDirectory
In bootstrap.php
meines Unit-Tests, aber es funktioniert nicht
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(APPLICATION_PATH . '/controllers');
Der einzige Weg, der funktioniert, ist die Verwendung setUp()
.Warum das?
ENDE UPDATE 23. Dez
Beim Unit-Testen meiner Controller-Plugins erhalte ich die obige Fehlermeldung.Ich verwende keine Module.In meiner Bootstrap.php für Unit-Tests habe ich sogar versucht, etwas hinzuzufügen
$front = Zend_Controller_Front::getInstance();
$front->setDefaultModule('default');
Aber es funktioniert immer noch nicht.Wie auch immer, meine Bootstrap.php sieht so aus Das
AKTUALISIEREN:Der Fehler sieht ungefähr so aus
Es gab 2 Fehler:
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
AKTUALISIEREN
Ich habe versucht, hinzuzufügen
public function setUp() {
$front = Zend_Controller_Front::getInstance();
$front->setDefaultModule('default');
}
dann funktioniert 1 Teil.
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');
}
Lösung
Die Lösung scheint darin zu bestehen, dies zu haben setUp()
.
$this->getFrontController()->setControllerDirectory(APPLICATION_PATH . '/controllers');
Allerdings suche ich immer noch nach Antworten auf meine im Update gestellten Fragen
1.Warum wird dieser Wert nicht von application.ini initialisiert?
In
application.ini
, Ich habe[production] resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" [testing : production] // didn't change anything regarding modules nor controllers
2.Ich habe versucht, das einzustellen
controllerDirectory
Inbootstrap.php
meines Unit -Tests, aber es funktioniert nicht$front = Zend_Controller_Front::getInstance(); $front->setControllerDirectory(APPLICATION_PATH
.'/controller');
Der einzige Weg, der funktioniert, ist die Verwendung
setUp()
.Warum das?
Andere Tipps
Ich hatte den gleichen Fehler, aber das hat den Fehler überhaupt nicht behoben.Weder in der setUp()-Methode noch in einem Plugin.Aber das Festlegen der Bootstrap-Ressource löste das Problem, obwohl sie normalerweise von meiner Anwendung festgelegt wird.In meinem Fall hat Folgendes funktioniert:
if($this->getFrontController()->getParam('bootstrap') === null) {
$this->getFrontController()->setParam('bootstrap', $app->getBootstrap());
}