Julien D Julien D - 3 years ago 305
PHP Question

codeception : Setting the "doctrine" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0

My project is a Symfony 3.3.9 project with Doctrine ORM.
I use codeception 2.3.6 with the module Doctrine2, I follow this article : http://codeception.com/docs/modules/Doctrine2

My config of codeception is :

#tests/functional.suite.yml
actor: FunctionalTester
modules:
enabled:
- \Helper\Functional
- PhpBrowser:
url: http://localhost
- Symfony
- Doctrine2:
depends: Symfony
cleanup: true


When I run the suite of tests with this command

./vendor/bin/codecept run functional


The tests pass very well with Success, but deprecated messages are thrown :

Setting the "doctrine" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0

When I remove the configuration of Doctrine2 module from functional.suite.yml

#tests/functional.suite.yml
actor: FunctionalTester
modules:
enabled:
- \Helper\Functional
- PhpBrowser:
url: http://localhost
- Symfony


I have to remove the calls of
$I->grabEntityFromRepository()
in my tests classes, and the deprecated disappear

Answer Source

I have the same issue on my projects. The issue is opened on github https://github.com/Codeception/Codeception/issues/4318

The problem is not into Doctrine2 module of codeception but into Symfony module of codeception.

The method Codeception\Module\Symfony::_getEntityManager() want to persist 3 services doctrine, doctrine.orm.default_entity_manager, doctrine.dbal.backend_connection

public function _getEntityManager()
{
    if ($this->kernel === null) {
        $this->fail('Symfony2 platform module is not loaded');
    }
    if (!isset($this->permanentServices[$this->config['em_service']])) {
        // try to persist configured EM
        $this->persistService($this->config['em_service'], true);

        if ($this->_getContainer()->has('doctrine')) {
            $this->persistService('doctrine', true);
        }
        if ($this->_getContainer()->has('doctrine.orm.default_entity_manager')) {
            $this->persistService('doctrine.orm.default_entity_manager', true);
        }
        if ($this->_getContainer()->has('doctrine.dbal.backend_connection')) {
            $this->persistService('doctrine.dbal.backend_connection', true);
        }
    }
    return $this->permanentServices[$this->config['em_service']];
}

The error is triggered from Codeception\Lib\Connector\Symfony::rebootKernel() :

public function rebootKernel()
{
    foreach ($this->persistentServices as $serviceName => $service) {
        $this->container->set($serviceName, $service);
    }  
}

You can comment the issue of github, it is not closed right now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download