0

我正在按照本指南http://devblog.x2k.co.uk/getting-the-servicemanager-into-the-test-environment-and-dependency-injection/让我的 phpunit 东西运行。

但是在我按照教程添加此代码之后。

 $serviceManager->get('ModuleManager')->loadModules();

我收到以下错误,找不到任何线索来解决!

`PHP Fatal error:  Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ModuleManager' in /home/dan/www/d2zfcuser/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:518
Stack trace:
#0 /home/dan/www/d2zfcuser/tests/Bootstrap.php(23): Zend\ServiceManager\ServiceManager->get('ModuleManager')
#1 /home/dan/www/d2zfcuser/tests/Bootstrap.php(32): Bootstrap::init()
#2 /usr/share/php/PHPUnit/Util/Fileloader.php(95): include_once('/home/dan/www/d...')
#3 /usr/share/php/PHPUnit/Util/Fileloader.php(79): PHPUnit_Util_Fileloader::load('/home/dan/www/d...')
#4 /usr/share/php/PHPUnit/TextUI/Command.php(867): PHPUnit_Util_Fileloader::checkAndLoad('/home/dan/www/d...')
#5 /usr/share/php/PHPUnit/TextUI/Command.php(620): PHPUnit_TextUI_Command->handleBootstrap('/home/dan/www/d...')
#6 /usr/share/php/PHPUnit/TextUI/Command.php(139): PHPUnit_TextUI_Command->handleArguments(Array)
#7 /usr/share/php in /home/dan/www/d2zfcuser/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 518`

请帮我解决这个问题。

4

1 回答 1

1

使用此处提供的 Bootstrap 后,此问题已得到解决。

所以上面教程中使用的 Bootstrap 就是这个问题背后的问题。终于解决了。

于 2013-12-29T06:43:23.657 回答