diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php index 1739dc3aea..665869ba9a 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php @@ -79,7 +79,7 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface uasort($subscribers, $sortFunc); foreach ($subscribers as $id => $instance) { if ($container->getDefinition($id)->isAbstract()) { - throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id)); + continue; } $em->addMethodCall('addEventSubscriber', array(new Reference($id))); @@ -95,7 +95,7 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface uasort($listeners, $sortFunc); foreach ($listeners as $id => $instance) { if ($container->getDefinition($id)->isAbstract()) { - throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id)); + continue; } $em->addMethodCall('addEventListener', array( diff --git a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php index 25776f8669..8a29331b0b 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php @@ -18,9 +18,6 @@ use Symfony\Component\DependencyInjection\Definition; class RegisterEventListenersAndSubscribersPassTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - */ public function testExceptionOnAbstractTaggedSubscriber() { $container = $this->createBuilder(); @@ -32,12 +29,10 @@ class RegisterEventListenersAndSubscribersPassTest extends TestCase $container->setDefinition('a', $abstractDefinition); $this->process($container); + $this->assertSame(array(), $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls()); } - /** - * @expectedException \InvalidArgumentException - */ - public function testExceptionOnAbstractTaggedListener() + public function testAbstractTaggedListenerIsSkipped() { $container = $this->createBuilder(); @@ -48,6 +43,7 @@ class RegisterEventListenersAndSubscribersPassTest extends TestCase $container->setDefinition('a', $abstractDefinition); $this->process($container); + $this->assertSame(array(), $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls()); } public function testProcessEventListenersWithPriorities() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php index 9f465edda5..535a8bea20 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php @@ -62,10 +62,6 @@ class AddConsoleCommandPassTest extends TestCase ); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract. - */ public function testProcessThrowAnExceptionIfTheServiceIsAbstract() { $container = new ContainerBuilder(); @@ -77,6 +73,8 @@ class AddConsoleCommandPassTest extends TestCase $container->setDefinition('my-command', $definition); $container->compile(); + + $this->assertSame(array(), $container->getParameter('console.command.ids')); } /** diff --git a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php index 632fb2e9e9..c6459d5e29 100644 --- a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php +++ b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php @@ -32,7 +32,7 @@ class AddConsoleCommandPass implements CompilerPassInterface $definition = $container->getDefinition($id); if ($definition->isAbstract()) { - throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id)); + continue; } $class = $container->getParameterBag()->resolveValue($definition->getClass()); diff --git a/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php b/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php index c6af56a0a1..f5199fee35 100644 --- a/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php +++ b/src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php @@ -50,11 +50,7 @@ class AddConsoleCommandPassTest extends TestCase ); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract. - */ - public function testProcessThrowAnExceptionIfTheServiceIsAbstract() + public function testProcessSkipAbstractDefinitions() { $container = new ContainerBuilder(); $container->setResourceTracking(false); @@ -66,6 +62,8 @@ class AddConsoleCommandPassTest extends TestCase $container->setDefinition('my-command', $definition); $container->compile(); + + $this->assertSame(array(), $container->getParameter('console.command.ids')); } /** diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 431ea21a67..aaa96fffde 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -63,7 +63,7 @@ class RegisterListenersPass implements CompilerPassInterface foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) { $def = $container->getDefinition($id); if ($def->isAbstract()) { - throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id)); + continue; } foreach ($events as $event) { @@ -90,7 +90,7 @@ class RegisterListenersPass implements CompilerPassInterface foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) { $def = $container->getDefinition($id); if ($def->isAbstract()) { - throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id)); + continue; } // We must assume that the class value has been correctly filled, even if the service is created by a factory diff --git a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php index 13810ce433..40821377a5 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php @@ -87,10 +87,6 @@ class RegisterListenersPassTest extends TestCase $registerListenersPass->process($builder); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded. - */ public function testAbstractEventListener() { $container = new ContainerBuilder(); @@ -99,13 +95,11 @@ class RegisterListenersPassTest extends TestCase $registerListenersPass = new RegisterListenersPass(); $registerListenersPass->process($container); + + $this->assertSame(array(), $container->getDefinition('event_dispatcher')->getMethodCalls()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded. - */ - public function testAbstractEventSubscriber() + public function testAbstractEventSubscriberIsSkipped() { $container = new ContainerBuilder(); $container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', array()); @@ -113,6 +107,8 @@ class RegisterListenersPassTest extends TestCase $registerListenersPass = new RegisterListenersPass(); $registerListenersPass->process($container); + + $this->assertSame(array(), $container->getDefinition('event_dispatcher')->getMethodCalls()); } public function testEventSubscriberResolvableClassName()