Skip to content

Commit

Permalink
bug #26960 [Messenger] Allow sender tag name omission (soyuka)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.1-dev branch.

Discussion
----------

[Messenger] Allow sender tag name omission

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | na
| License       | MIT
| Doc PR        | na

Tag attributes are not mandatory.

Commits
-------

a473791 [Messenger] Allow sender tag name omission
  • Loading branch information
sroze committed Apr 17, 2018
2 parents 507989d + a473791 commit 4af9003
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Expand Up @@ -157,7 +157,11 @@ private function registerReceivers(ContainerBuilder $container)
$receiverMapping = array();
foreach ($container->findTaggedServiceIds('messenger.receiver') as $id => $tags) {
foreach ($tags as $tag) {
$receiverMapping[$tag['name'] ?? $id] = new Reference($id);
$receiverMapping[$id] = new Reference($id);

if (isset($tag['name'])) {
$receiverMapping[$tag['name']] = $receiverMapping[$id];
}
}
}

Expand All @@ -171,8 +175,8 @@ private function registerSenders(ContainerBuilder $container)
foreach ($tags as $tag) {
$senderLocatorMapping[$id] = new Reference($id);

if ($tag['name']) {
$senderLocatorMapping[$tag['name']] = new Reference($id);
if (isset($tag['name'])) {
$senderLocatorMapping[$tag['name']] = $senderLocatorMapping[$id];
}
}
}
Expand Down
Expand Up @@ -99,7 +99,17 @@ public function testItRegistersReceivers()

(new MessengerPass())->process($container);

$this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
$this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class), AmqpReceiver::class => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
}

public function testItRegistersReceiversWithoutTagName()
{
$container = $this->getContainerBuilder();
$container->register(AmqpReceiver::class, AmqpReceiver::class)->addTag('messenger.receiver');

(new MessengerPass())->process($container);

$this->assertEquals(array(AmqpReceiver::class => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
}

public function testItRegistersSenders()
Expand All @@ -112,6 +122,16 @@ public function testItRegistersSenders()
$this->assertEquals(array('amqp' => new Reference(AmqpSender::class), AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
}

public function testItRegistersSenderWithoutTagName()
{
$container = $this->getContainerBuilder();
$container->register(AmqpSender::class, AmqpSender::class)->addTag('messenger.sender');

(new MessengerPass())->process($container);

$this->assertEquals(array(AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Invalid handler service "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessageHandler": message class "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessage" used as argument type in method "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessageHandler::__invoke()" does not exist.
Expand Down

0 comments on commit 4af9003

Please sign in to comment.