草庐IT

php - codeception : Setting the "doctrine" pre-defined service is deprecated since Symfony 3. 3 并且 Symfony 4.0 将不再支持

coder 2024-05-02 原文

我的项目是一个带有 Doctrine ORM 的 Symfony 3.3.9 项目。 我将 codeception 2.3.6 与模块 Doctrine2 一起使用,我关注这篇文章:http://codeception.com/docs/modules/Doctrine2

我的codeception配置是:

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

当我使用此命令运行测试套件时

./vendor/bin/codecept run functional

测试顺利通过并成功,但会抛出弃用的消息:

设置“doctrine”预定义服务自 Symfony 3.3 起已弃用,Symfony 4.0 将不再支持

当我从 functional.suite.yml 中删除 Doctrine2 模块的配置时

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

我必须在我的测试类中删除对 $I->grabEntityFromRepository() 的调用,然后弃用的就消失了

最佳答案

我的项目也有同样的问题。 该问题在 github 上打开 https://github.com/Codeception/Codeception/issues/4318

问题不在codeception的Doctrine2模块,而是在codeception的Symfony模块。

方法 Codeception\Module\Symfony::_getEntityManager() 想要持久化 3 个服务 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']];
}

错误是从 Codeception\Lib\Connector\Symfony::rebootKernel() 触发的:

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

github的issue可以评论,目前还没有关闭。

编辑:您可以在配置文件中定义 error_level 并添加 ~E_USER_DEPRECATED:

#tests/functional.suite.yml
actor: FunctionalTester
modules:
    enabled:
        - \Helper\Functional
        - PhpBrowser:
            url: http://localhost 
        - Symfony 
        - Doctrine2:
            depends: Symfony
            cleanup: true
error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_USER_DEPRECATED"

http://codeception.com/docs/04-FunctionalTests#Error-Reporting

关于php - codeception : Setting the "doctrine" pre-defined service is deprecated since Symfony 3. 3 并且 Symfony 4.0 将不再支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46504969/

有关php - codeception : Setting the "doctrine" pre-defined service is deprecated since Symfony 3. 3 并且 Symfony 4.0 将不再支持的更多相关文章

随机推荐