zend-framework2 – Zend Framework 2教程:Module(Application)无法初始
发布时间:2020-05-25 09:45:58 所属栏目:PHP 来源:互联网
导读:我正在遵循官方的Zend Framework 2教程2.1版.在 Unit Testing部分,我应该在模块/应用程序/测试中运行phpunit,我遇到以下问题: user@xubuntu1210:~/Desktop/zf2-tutorial/module/Application/test$phpunitPHPUnit 3.7.13 by Sebastian Bergmann.Configu
|
我正在遵循官方的Zend Framework 2教程2.1版.在 Unit Testing部分,我应该在模块/应用程序/测试中运行phpunit,我遇到以下问题: user@xubuntu1210:~/Desktop/zf2-tutorial/module/Application/test$phpunit PHPUnit 3.7.13 by Sebastian Bergmann. Configuration read from /home/user/Desktop/zf2-tutorial/module/Application/test/phpunit.xml.dist E Time: 0 seconds,Memory: 4.00Mb There was 1 error: 1) ApplicationTestControllerIndexControllerTest::testIndexActionCanBeAccessed ZendModuleManagerExceptionRuntimeException: Module (Application) could not be initialized. /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:140 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:81 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:460 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:204 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:100 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:239 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:146 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:173 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:193 /home/user/Desktop/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:236 /home/user/Desktop/zf2-tutorial/module/Application/test/ApplicationTest/Controller/IndexControllerTest.php:20 FAILURES! Tests: 1,Assertions: 0,Errors: 1. 我从教程中复制了IndexControllerTest.php的内容. <?php
namespace ApplicationTestController;
use ZendTestPHPUnitControllerAbstractHttpControllerTestCase;
class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
$this->setApplicationConfig(
include '/home/user/Desktop/zf2-tutorial/config/application.config.php'
);
parent::setUp();
}
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/'); // this is line 20
$this->assertResponseStatusCode(200);
$this->assertModule('application');
$this->assertControllerName('application_index');
$this->assertControllerClass('IndexController');
$this->assertMatchedRouteName('home');
}
}
我不知道为什么应用程序不会初始化,我会欣赏任何指针. 这是一个自动加载问题,可能与config / application.config.php中的module_paths选项相关(在本教程中,它是/path/to/application/config/test/application.config.php中的一个).该application.config.php可能如下所示: return array(
'modules' => array(
'Application','Album',),'module_listener_options' => array(
'module_paths' => array(
'./module','./vendor',);
要解决您的问题,请将./module的值更改为绝对路径,例如__DIR__. ‘/../module,假设application.config.php在应用程序的根目录中的config /中. 要澄清:问题发生是因为./module是一个相对于你的cwd的路径.你的cwd运行phpunit是在测试目录里,哪里没有(显然)任何模块目录. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
