Skip to content

zend framework 2.4 "Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ApplicationConfig"

We had some controller tests in our test cases and the following error was thrown, after we updated to zend framework 2.4.


Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ApplicationConfig

/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:555
/vendor/zendframework/zendframework/library/Zend/Mvc/Service/ModuleManagerFactory.php:41
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:939
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:1097
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:638
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:598
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:530
/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:253
/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:164
/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:73
//MyControllerTest.php:124

"MyControllerTest" extends "Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase". What we did to solve the problem was adding the following lines of code in our "setUp" method.


$applicationConfigurationPath = DIR . strrepeat('/..', ) . '/config/application.config.php';
if (!isfile($applicationConfigurationPath)) {
    $message = 'application configuration needed and not found in path "' . $applicationConfigurationPath . '"';

$this->fail($message);

} $applicationConfiguration = require $applicationConfigurationPath; unset($applicationConfiguration['modulelisteneroptions']['configglobpaths']); $applicationConfiguration['modules'] = array();

$this->setApplicationConfig($applicationConfiguration);


Thats it, hope it helps.

Translate to de es fr it pt ja

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

The author does not allow comments to this entry

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options