首页 > 解决方案 > AutoWire services_test.yaml -> 没有 ID 为“service.a”的节点

问题描述

在 SF4.2 正常路线中迁移到 AutoWire 后,单元测试无法正常工作。

服务.yaml:

services:
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        public: false       # Allows optimizing the container by removing unused services; this also means

# enable AW on controllers
    KRNApiBundle\Controller\:
        resource: '../../Controller'
        tags: ['controller.service_arguments']

# AutoWireAliases
    MyClass: '@service.a'

    service.a:
      class: MyClass

services_test.yaml,有一些,但没有 service.a 定义/重载

运行,任何测试,它在(WebTestCase)失败:

$client = static::createClient();

InvalidArgumentException: There is no node with id "service.a".

当我复制 to 的定义时service.a -services_test.yaml它有效。但是我想要并且必须避免两次定义所有服务(为错误引入了巨大的表面)

标签: symfonysymfony4

解决方案


看起来像一个错误 - 应该由https://github.com/symfony/symfony/pull/29393修复


推荐阅读