2012-12-25 142 views
8

我剛開始使用Zend Framework 2和Doctrine。我想爲我的相冊模塊設置單元測試。phpunit單元測試錯誤zf2 doctrine

當我從命令提示符下運行c:\wamp\www\zf2-tutorial\module\Album\test > phpunit, 我獲得以下錯誤:

PHPUnit 3.7.10 by Sebastian Bergmann. 

Configuration read from C:\wamp\www\zf2-tutorial\module\Album\test\phpunit.xml.d 
ist 

.FFE 

Time: 2 seconds, Memory: 8.25Mb 

There was 1 error: 

1) AlbumTest\Controller\AlbumControllerTest::testIndexActionCanBeAccessed 
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\Serv 
iceManager::get was unable to fetch or create an instance for doctrine.entityman 
ager.orm_default 

C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Service 
Manager\ServiceManager.php:452 
C:\wamp\www\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:2 
5 
C:\wamp\www\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:3 
3 
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Con 
troller\AbstractActionController.php:88 
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventMa 
nager\EventManager.php:464 
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventMa 
nager\EventManager.php:208 
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Con 
troller\AbstractController.php:107 
C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT 
est.php:71 

-- 


There were 2 failures: 

1) AlbumTest\Controller\AlbumControllerTest::testDeleteActionCanBeAccessed 
Failed asserting that 302 matches expected 200. 

C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT 
est.php:54 

2) AlbumTest\Controller\AlbumControllerTest::testEditActionCanBeAccessed 
Failed asserting that 302 matches expected 200. 

C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT 
est.php:64 

FAILURES! 
Tests: 4, Assertions: 3, Failures: 2, Errors: 1. 

問題的根源似乎是: 的Zend \的ServiceManager \異常\ ServiceNotFoundException的:Zend的\的ServiceManager \ SERV iceManager :: get無法取得或爲doctrine.entityman創建實例 ager.orm_default from test ..

我不明白這一點,請大家幫忙!

+0

你能看到webapp嗎?這可能是一個問題,因爲Doctrine安裝不正確或配置不正確。 –

+0

感謝Jurian的回覆。是的,Web應用程序運行良好,並且Doctrine也正確安裝。添加,編輯,列表和刪除功能可以正常使用Doctrine for Album模塊。 – Prashant

回答

17

好吧終於明白了! 我改變了我的TestConfig.php.dist模塊/專輯/測試裏面

<?php 
return array(
    'modules' => array(
     'DoctrineModule', 
     'DoctrineORMModule', 
     'Album', 
    ), 
    'module_listener_options' => array(
     'config_glob_paths' => array(
      '../../../config/autoload/{,*.}{global,local}.php', 
     ), 
     'module_paths' => array(
      'module', 
      'vendor', 
     ), 
    ), 
); 

所以基本上只是增加了兩個丟失的模塊,DoctrineModule和DoctrineORMModule,以及PHPUnit命令顯示沒有錯誤!

希望它可以幫助別人。

+0

謝謝,幫了我很多! – Ron

+0

謝謝!我一直在尋找幾個小時。它終於有效! –