【问题标题】:Symfony 4. Special container that allows fetching private servicesSymfony 4. 允许获取私有服务的特殊容器
【发布时间】:2019-02-01 12:23:35
【问题描述】:

页面上https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing站着

// gets the special container that allows fetching private services
$container = self::$container;

但它在功能测试中对我没有影响。只有当我将服务定义为公开时,我才能使用$container->set('service.mail', $someService);

这里有什么问题?

【问题讨论】:

标签: unit-testing symfony symfony4


【解决方案1】:

您是否使用文件 services_test.yaml?

我添加了所有需要包含在测试中的服务我向您展示了我的文件的一部分:

services:
    _defaults:
        public: true

    # If you need to access services in a test, create an alias
    # and then fetch that alias from the container. As a convention,
    # aliases are prefixed with test. For example:
    #
    # test.App\Service\MyService: '@App\Service\MyService'

    test.app.service.user_management.user_service:
        alias: App\Service\UserManagement\UserService

    test.app.service.weight.weight_service:
        alias: App\Service\Weight\WeightService

当你这样做时,其余的应该就位。

【讨论】:

  • 如果你写_defaults: public: true,它可以工作。但它也应该在没有public: true 的情况下工作
猜你喜欢
  • 2018-12-24
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
  • 2013-11-24
  • 2012-10-20
相关资源
最近更新 更多