From bbd96cc9a0ecbd671a40c8c027846bda0d8b2ab6 Mon Sep 17 00:00:00 2001 From: xjm Date: Tue, 21 Feb 2017 09:37:03 +0000 Subject: [PATCH] Issue #2852515 by dawehner, timmillwood: $interface is still set from the previous loop in tagged services compilation --- .../DependencyInjection/Compiler/TaggedHandlersPass.php | 1 + .../Compiler/TaggedHandlersPassTest.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php index 04b56aa44c3a..3386e6af6bd7 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php @@ -77,6 +77,7 @@ class TaggedHandlersPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { foreach ($container->findTaggedServiceIds('service_collector') as $consumer_id => $passes) { foreach ($passes as $pass) { + $interface = NULL; $tag = isset($pass['tag']) ? $pass['tag'] : $consumer_id; $method_name = isset($pass['call']) ? $pass['call'] : 'addHandler'; $required = isset($pass['required']) ? $pass['required'] : FALSE; diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index 2eeb603b4c77..6719cbc96fcc 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -64,13 +64,16 @@ class TaggedHandlersPassTest extends UnitTestCase { * Tests consumer with missing interface in non-production environment. * * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException - * @expectedExceptionMessage Service consumer 'consumer_id' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface. + * @expectedExceptionMessage Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface. * @covers ::process */ public function testProcessMissingInterface() { $container = $this->buildContainer(); $container - ->register('consumer_id', __NAMESPACE__ . '\InvalidConsumer') + ->register('consumer_id0', __NAMESPACE__ . '\ValidConsumer') + ->addTag('service_collector'); + $container + ->register('consumer_id1', __NAMESPACE__ . '\InvalidConsumer') ->addTag('service_collector'); $handler_pass = new TaggedHandlersPass();