function TaggedHandlersPassTest::testProcessChildDefinition

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php \Drupal\Tests\Core\DependencyInjection\Compiler\TaggedHandlersPassTest::testProcessChildDefinition()

Tests child handler with parent service.

File

core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php, line 300

Class

TaggedHandlersPassTest
Tests Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass.

Namespace

Drupal\Tests\Core\DependencyInjection\Compiler

Code

public function testProcessChildDefinition() : void {
  $container = $this->buildContainer();
  $container->register('consumer_id', __NAMESPACE__ . '\\ValidConsumer')
    ->addTag('service_collector');
  $container->register('root_handler', __NAMESPACE__ . '\\ValidHandler');
  $container->addDefinitions([
    'parent_handler' => new ChildDefinition('root_handler'),
    'child_handler' => (new ChildDefinition('parent_handler'))->addTag('consumer_id'),
  ]);
  $handler_pass = new TaggedHandlersPass();
  $handler_pass->process($container);
  $method_calls = $container->getDefinition('consumer_id')
    ->getMethodCalls();
  $this->assertCount(1, $method_calls);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.