5

I have 2 files.

services.yaml

imports:
    - { resource: services/service_test.yaml }

services:
    _defaults:
        autowire: true
        autoconfigure: true

and service_test.yaml

services:
    _defaults:
      autowire: true
      autoconfigure: true

    App\Test\TestAbstract:
      abstract: true

    App\Test\TestA:
      parent: App\Test\TestAbstract
      autowire: false
      autoconfigure: false
      tags:
        - { name: app.test }

    App\Test\TestManager:
      arguments: [!tagged { tag: 'app.test' }]

my class TestManager has a constructor

public function __construct(iterable $tests, LoggerInterface $logger)
{
    dump($tests);
    $this->logger = $logger;
}

With that configuration I have the error:

Cannot autowire service "App\Test\TestManager": argument "$tests" of method "__construct()" is type-hinted "iterable", you should configure its value explicitly.

How can I get my tagged services with !tag ?

Sancho
  • 1,288
  • 2
  • 25
  • 50

2 Answers2

1

App\Test\TestManager: arguments: [!tagged { tag: 'app.test' }]

In the arguments i suggest to try adding !tagged_iterator app.test

0

If any one is here to find a solution, try to initiate an empty array into the constructor by adding = [].

Example:

public function __construct(iterable $tests = [], LoggerInterface $logger)

Anouar
  • 23
  • 4