在不称为“测试”的环境中使用 Symfony TestContainer

问题描述 投票:0回答:1

我在 CodeCception 中编写了一个单元测试,我的配置

Unit.suite.yml

actor: UnitTester
modules:
    enabled:
      - Asserts
      - Symfony:
          environment: 'autotest'
step_decorators: ~

我有一个单独的环境用于在管道中运行单元测试 -

autotest
,我想通过
Codeception\Module\Symfony->grabService
使用我的服务,但我收到错误消息,该服务应该是公共的,但是,如果我使用测试环境,Symfony加载
Symfony\Bundle\FrameworkBundle\Test\TestContainer
并且没有错误,有什么办法让Symfony为
autotest
环境加载这个容器吗?

我尝试通过

config/packages/services.yml

中公开所有服务
when@autotest:
  services:
    _defaults:
      public: true
      autowire: true
      autoconfigure: true

我还尝试添加每个单独的服务并在其上添加

public: true
,但没有帮助

symfony codeception
1个回答
1
投票

在您的自定义环境中将

framework.test
设置为
true

例如

#framework.yaml

when@test:
  framework:
    test: true
    csrf_protection: false
    session:
      storage_factory_id: session.storage.factory.mock_file


when@autotest:
  framework:
    test: true
    csrf_protection: false
    session:
      storage_factory_id: session.storage.factory.mock_file

我认为这可能可以解决问题。希望没有其他网站的“测试”环境被“假定”为字面意义上的“测试”。

© www.soinside.com 2019 - 2024. All rights reserved.