Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DoctrineBridge] Abstract Doctrine Subscribers with tags #11160

Merged
merged 1 commit into from Aug 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -68,6 +68,10 @@ public function process(ContainerBuilder $container)

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));
}

$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
}
}
Expand All @@ -78,6 +82,10 @@ public function process(ContainerBuilder $container)

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));
}

$em->addMethodCall('addEventListener', array(
array_unique($instance['event']),
isset($instance['lazy']) && $instance['lazy'] ? $id : new Reference($id),
Expand Down
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class RegisterEventListenersAndSubscribersPassTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -23,6 +24,38 @@ protected function setUp()
}
}

/**
* @expectedException InvalidArgumentException
*/
public function testExceptionOnAbstractTaggedSubscriber()
{
$container = $this->createBuilder();

$abstractDefinition = new Definition('stdClass');
$abstractDefinition->setAbstract(true);
$abstractDefinition->addTag('doctrine.event_subscriber');

$container->setDefinition('a', $abstractDefinition);

$this->process($container);
}

/**
* @expectedException InvalidArgumentException
*/
public function testExceptionOnAbstractTaggedListener()
{
$container = $this->createBuilder();

$abstractDefinition = new Definition('stdClass');
$abstractDefinition->setAbstract(true);
$abstractDefinition->addTag('doctrine.event_listener', array('event' => 'test'));

$container->setDefinition('a', $abstractDefinition);

$this->process($container);
}

public function testProcessEventListenersWithPriorities()
{
$container = $this->createBuilder();
Expand Down