13

バージョン2.1の公式ZendFramework2チュートリアルに従っています。module / Application / testで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');
    }
}

アプリケーションが初期化されない理由がわからないので、ポインタをいただければ幸いです。

4

2 に答える 2

35

module_pathsこれは、 のオプションに関連している可能性があるオートロードの問題ですconfig/application.config.php(チュートリアルでは、 にあるものです/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.phpconfig/

明確にするために:問題./moduleは、あなたのcwd. 実行cwdphpunitは、(明らかに)ディレクトリがないテストディレクトリ内にありmoduleます。

于 2013-02-12T16:02:45.743 に答える
-1

「モジュール」でアプリケーションを定義する必要があるルート構成フォルダーの application.config ファイルを確認します。

サンプルコード:

'modules' => array(
        'Application',
        'FrontEnd',
              ),
于 2013-02-09T14:26:51.840 に答える