8

I've just started with Zend framework 2, with Doctrine. I want to set up unit testing for my Album module.

When I run c:\wamp\www\zf2-tutorial\module\Album\test > phpunit from command prompt, I get following error:

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. 

The root of the issue seems to be: Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\Serv iceManager::get was unable to fetch or create an instance for doctrine.entityman ager.orm_default from test..

I don't understand this, please help!

2
  • Are you able to see the webapp? It might be a problem because Doctrine is not installed correctly or not configured correctly. Commented Dec 25, 2012 at 11:08
  • Thanks for the reply Jurian. Yes the webapp runs fine, and Doctrine is also installed correctly. The add, edit, list and delete functions are working fine with Doctrine for Album module. Commented Dec 25, 2012 at 13:42

1 Answer 1

18

Okay finally got it!! I changed my TestConfig.php.dist inside module/Album/test to

<?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', ), ), ); 

so basically just added two missing modules, DoctrineModule and DoctrineORMModule, and the phpunit command showed no errors!

Hope it helps others.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!! I have been searching for hours and hours. It finally works!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.