2013-02-08 9 views
13

バージョン2.1の公式Zend Framework 2チュートリアルに従っています。私はモジュール/アプリケーション/テストにはPHPUnitを実行することになっていますUnit Testingセクションでは、私は次のような問題に実行しています:Zend Framework 2チュートリアル:モジュール(アプリケーション)を初期化できませんでした

[email protected]:~/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'); 
    } 
} 

私はアプリケーションが初期化されない理由を知りません。私はポインタに感謝します。

+0

私の問題は、私のモジュールフォルダとファイルにあるアクセス許可でした。 (私はUbuntu PCに入っています) – leticia

答えて

-1

アプリケーションを 'modules'で定義する必要があるルート設定フォルダ内のapplication.configファイルを確認します。

サンプルコード:

'modules' => array(
     'Application', 
     'FrontEnd', 
      ), 
+2

私はそれがそれではないことを恐れています。私のconfig/application.config.phpに 'modules '=>配列( ' Application '、 ' Album '、 )、 ' –

31

これはconfig/application.config.phpmodule_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/です。

明確にする:cwdに相対的なパスであるため、./moduleのパスが原因で問題が発生します。 phpunitを実行している場合のcwdは、テストディレクトリ内にあります。moduleディレクトリはありません(明らかに)。

+0

ありがとうございます@Ocramius私はこれを試しましたが、私は 'PHP致命的なエラー:22行目の/var/www/test/zf2-tutorial/module/Application/test/ApplicationTest/Controller/IndexControllerTest.phpの未定義のメソッドApplicationTest \ Controller \ IndexControllerTest :: assertModule()を呼び出して、 1つの問題を解決し、別の問題を引き起こす。 –

+0

さて、問題は解決されているようです( 'IndexControllerTest :: assertModule'は存在しません)。私たちはそれについてチャットすることができます。 – Ocramius

+0

このユーザーガイドでは更新が必要なものがたくさんあるように、すべての参照用に 'assertModuleName'が必要です。 –

関連する問題