错误 [ModuleException] Doctrine2:无法访问模块

error [ModuleException] Doctrine2: Module can't be accessed

我无法按照 https://codeception.com/docs/modules/Doctrine2 中的文档进行操作。这是错误 [ModuleException] Doctrine2: Module can't be accessed

我想在单元测试中访问 $entityManger。学说 bootstrap.php 具有 createEntityManager 的功能 returns entityManager

#codeception.yml
suites:
    unit:
        path: .
        actor: UnitTester
        modules:
            enabled:
                # add more modules here
                - Asserts
settings:
    bootstrap: ../config/bootstrap.php
    shuffle: true
    lint: true
paths:
    tests: tests
    output: tests/_output
    support: tests/_support
    data: tests

# unit.suite.yml
actor: UnitTester
modules:
  enabled:
    - Asserts
    - Doctrine2:
      connection_callback: ['createEntityManager']
      cleanup: true # All doctrine queries will be wrapped in a transaction, which will be rolled back at the end of each test
    - \Helper\Unit

您的问题是您在 codeception.yml 文件中配置了单元套件,因此您的 unit.suite.yml 被忽略了。

从 codeception.yml 中删除此部分或删除 unit.suite.yml 并更新 codeception.yml

suites:
    unit:
        path: .
        actor: UnitTester
        modules:
            enabled:
                # add more modules here
                - Asserts