Revert "minor #22039 Skip abstract definitions in compiler passes (chalasr)"
This reverts commit207d068a40
, reversing changes made to4836007172
.
This commit is contained in:
parent
46fc0b9363
commit
cd06c1297b
@ -79,7 +79,7 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
||||
uasort($subscribers, $sortFunc);
|
||||
foreach ($subscribers as $id => $instance) {
|
||||
if ($container->getDefinition($id)->isAbstract()) {
|
||||
continue;
|
||||
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
|
||||
}
|
||||
|
||||
$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()) {
|
||||
continue;
|
||||
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
|
||||
}
|
||||
|
||||
$em->addMethodCall('addEventListener', array(
|
||||
|
@ -18,6 +18,9 @@ use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class RegisterEventListenersAndSubscribersPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExceptionOnAbstractTaggedSubscriber()
|
||||
{
|
||||
$container = $this->createBuilder();
|
||||
@ -29,10 +32,12 @@ 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 testAbstractTaggedListenerIsSkipped()
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExceptionOnAbstractTaggedListener()
|
||||
{
|
||||
$container = $this->createBuilder();
|
||||
|
||||
@ -43,7 +48,6 @@ 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()
|
||||
|
@ -62,6 +62,10 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
|
||||
*/
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
@ -73,8 +77,6 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertSame(array(), $container->getParameter('console.command.ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ class AddConsoleCommandPass implements CompilerPassInterface
|
||||
$definition = $container->getDefinition($id);
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
continue;
|
||||
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
|
||||
}
|
||||
|
||||
$class = $container->getParameterBag()->resolveValue($definition->getClass());
|
||||
|
@ -50,7 +50,11 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testProcessSkipAbstractDefinitions()
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
|
||||
*/
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
@ -62,8 +66,6 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertSame(array(), $container->getParameter('console.command.ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
|
||||
$def = $container->getDefinition($id);
|
||||
if ($def->isAbstract()) {
|
||||
continue;
|
||||
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
|
||||
}
|
||||
|
||||
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()) {
|
||||
continue;
|
||||
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
|
||||
}
|
||||
|
||||
// We must assume that the class value has been correctly filled, even if the service is created by a factory
|
||||
|
@ -87,6 +87,10 @@ 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();
|
||||
@ -95,11 +99,13 @@ class RegisterListenersPassTest extends TestCase
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($container);
|
||||
|
||||
$this->assertSame(array(), $container->getDefinition('event_dispatcher')->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testAbstractEventSubscriberIsSkipped()
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded.
|
||||
*/
|
||||
public function testAbstractEventSubscriber()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', array());
|
||||
@ -107,8 +113,6 @@ class RegisterListenersPassTest extends TestCase
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($container);
|
||||
|
||||
$this->assertSame(array(), $container->getDefinition('event_dispatcher')->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testEventSubscriberResolvableClassName()
|
||||
|
Reference in New Issue
Block a user