Search code examples
phpunit-testingzend-dbzend-framework3

PHPUnit test with Zend Framework 3


I got the error below in PHPUnit Controller test in Zend Framework 3:

Exception 'Zend\ServiceManager\Exception\ServiceNotCreatedException' with message 'Service with name "Zend\Db\Adapter\AdapterInterface" could not be created.

The same tests were working fine in Zend Framework 2. The following method in TestController is causing the issue.

$this->configureServiceManager($this->getApplicationServiceLocator());

is it deprecated?


Solution

  • After 4 days, I was able to figure out the problem and the fix.

     protected function updateConfig($config)
        {
            $config['db'] = [];
    
            $config['db']['driver'] = 'Pdo';
    
            return $config;
        }
    

    I had to the driver manually to fix the issue, Hope it will help others with the same error.