8000 Skip abstract definitions in compiler passes · symfony/symfony@fc1ba0d · GitHub
[go: up one dir, main page]

Skip to content

Commit fc1ba0d

Browse files
committed
Skip abstract definitions in compiler passes
1 parent eb6f3f7 commit fc1ba0d

File tree

7 files changed

+18
-30
lines changed

7 files changed

+18
-30
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function process(ContainerBuilder $container)
7979
uasort($subscribers, $sortFunc);
8080
foreach ($subscribers as $id => $instance) {
8181
if ($container->getDefinition($id)->isAbstract()) {
82-
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
82+
continue;
8383
}
8484

8585
$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
@@ -95,7 +95,7 @@ public function process(ContainerBuilder $container)
9595
uasort($listeners, $sortFunc);
9696
foreach ($listeners as $id => $instance) {
9797
if ($container->getDefinition($id)->isAbstract()) {
98-
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
98+
continue;
9999
}
100100

101101
$em->addMethodCall('addEventListener', array(

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
class RegisterEventListenersAndSubscribersPassTest extends TestCase
2020
{
21-
/**
22-
* @expectedException \InvalidArgumentException
23-
*/
2421
public function testExceptionOnAbstractTaggedSubscriber()
2522
{
2623
$container = $this->createBuilder();
@@ -32,12 +29,10 @@ public function testExceptionOnAbstractTaggedSubscriber()
3229
$container->setDefinition('a', $abstractDefinition);
3330

3431
$this->process($container);
32+
$this->assertSame(array(), $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls());
3533
}
3634

37-
/**
38-
* @expectedException \InvalidArgumentException
39-
*/
40-
public function testExceptionOnAbstractTaggedListener()
35+
public function testAbstractTaggedListenerIsSkipped()
4136
{
4237
$container = $this->createBuilder();
4338

@@ -48,6 +43,7 @@ public function testExceptionOnAbstractTaggedListener()
4843
$container->setDefinition('a', $abstractDefinition);
4944

5045
$this->process($container);
46+
$this->assertSame(array(), $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls());
5147
}
5248

5349
public function testProcessEventListenersWithPriorities()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ public function visibilityProvider()
6262
);
6363
}
6464

65-
/**
66-
* @expectedException \InvalidArgumentException
67-
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
68-
*/
6965
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
7066
{
7167
$container = new ContainerBuilder();
@@ -77,6 +73,8 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
7773
$container->setDefinition('my-command', $definition);
7874

7975
$container->compile();
76+
77+
$this->assertSame(array(), $container->getParameter('console.command.ids'));
8078
}
8179

8280
/**

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function process(ContainerBuilder $container)
3232
$definition = $container->getDefinition($id);
3333

3434
if ($definition->isAbstract()) {
35-
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
35+
continue;
3636
}
3737

3838
$class = $container->getParameterBag()->resolveValue($definition->getClass());

src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ public function visibilityProvider()
5050
);
5151
}
5252

53-
/**
54-
* @expectedException \InvalidArgumentException
55-
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
56-
*/
57-
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
53+
public function testProcessSkipAbstractDefinitions()
5854
{
5955
$container = new ContainerBuilder();
6056
$container->setResourceTracking(false);
@@ -66,6 +62,8 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
6662
$container->setDefinition('my-command', $definition);
6763

6864
$container->compile();
65+
66+
$this->assertSame(array(), $container->getParameter('console.command.ids'));
6967
}
7068

7169
/**

src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function process(ContainerBuilder $container)
6363
foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
6464
$def = $container->getDefinition($id);
6565
if ($def->isAbstract()) {
66-
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
66+
continue;
6767
}
6868

6969
foreach ($events as $event) {
@@ -90,7 +90,7 @@ public function process(ContainerBuilder $container)
9090
foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) {
9191
$def = $container->getDefinition($id);
9292
if ($def->isAbstract()) {
93-
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
93+
continue;
9494
}
9595

9696
// We must assume that the class value has been correctly filled, even if the service is created by a factory

src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ public function testValidEventSubscriber()
8787
$registerListenersPass->process($builder);
8888
}
8989

90-
/**
91-
* @expectedException \InvalidArgumentException
92-
* @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded.
93-
*/
9490
public function testAbstractEventListener()
9591
{
9692
$container = new ContainerBuilder();
@@ -99,20 +95,20 @@ public function testAbstractEventListener()
9995

10096
$registerListenersPass = new RegisterListenersPass();
10197
$registerListenersPass->process($container);
98+
99+
$this->assertSame(array(), $container->getDefinition('event_dispatcher')->getMethodCalls());
102100
}
103101

104-
/**
105-
* @expectedException \InvalidArgumentException
106-
* @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded.
107-
*/
108-
public function testAbstractEventSubscriber()
102+
public function testAbstractEventSubscriberIsSkipped()
109103
{
110104
$container = new ContainerBuilder();
111105
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', array());
112106
$container->register('event_dispatcher', 'stdClass');
113107

114108
$registerListenersPass = new RegisterListenersPass();
115109
$registerListenersPass->process($container);
110+
111+
$this->assertSame(array(), $container->getDefinition('event_dispatcher')->getMethodCalls());
116112
}
117113

118114
public function testEventSubscriberResolvableClassName()

0 commit comments

Comments
 (0)
0