Codeception SF4服务已初始化

时间:2018-02-13 14:43:27

标签: php symfony doctrine codeception

每次启动API套件时,第一次测试都会出现以下错误:

  

[Symfony \ Component \ DependencyInjection \ Exception \ InvalidArgumentException]“doctrine.orm.client_entity_manager”服务已初始化,您无法替换它。

其他测试运行良好,如果我再次启动测试,则错误消失。但是,如果我清除缓存或等待很长时间,错误将再次发生。

这是我的API套件配置:

actor: ApiTester
modules:
    enabled:
        - \Helper\SymfonyHelper:
            app_path: src
            environment: test
            em_service: doctrine.orm.client_entity_manager
        - Doctrine2:
            depends: \Helper\SymfonyHelper
            cleanup: true
        - REST:
            depends: \Helper\SymfonyHelper
            part: Json
            url: 'http://localhost/api'
        - \Helper\Api
        - Asserts

感谢您的帮助。

编辑:

这是帮手来源:

namespace Helper;

use Codeception\Module\Symfony;

class SymfonyHelper extends Symfony { /** * Check that an email is sent or count number of emails sent. * * @param int|null $nbEmail */ public function seeEmailIsSent(?int $nbEmail = null) { $profile = $this->getProfile(); if (!$profile) { $this->fail('Emails can\'t be tested without Profiler'); } if (!$profile->hasCollector('swiftmailer')) { $this->fail('Emails can\'t be tested without SwiftMailer connector'); }

    if (is_null($nbEmail)) {
        $this->assertGreaterThan(0, $profile->getCollector('swiftmailer')->getMessageCount());
    } else {
        $this->assertEquals($nbEmail, $profile->getCollector('swiftmailer')->getMessageCount());
    }
}

if (is_null($nbEmail)) { $this->assertGreaterThan(0, $profile->getCollector('swiftmailer')->getMessageCount()); } else { $this->assertEquals($nbEmail, $profile->getCollector('swiftmailer')->getMessageCount()); } }

0 个答案:

没有答案