zend-framework2 – Zend Framework 2教程:Module(Application)无法初始化

前端之家收集整理的这篇文章主要介绍了zend-framework2 – Zend Framework 2教程:Module(Application)无法初始化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在遵循官方的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) ApplicationTest\Controller\IndexControllerTest::testIndexActionCanBeAccessed
Zend\ModuleManager\Exception\RuntimeException: 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 ApplicationTest\Controller;

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;

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是在测试目录里,哪里没有(显然)任何模块目录.

原文链接:https://www.f2er.com/php/140114.html

猜你在找的PHP相关文章