Skip to content

Commit

Permalink
bug #35502 [Messenger] Fix bug when using single route with XML confi…
Browse files Browse the repository at this point in the history
…g (Nyholm)

This PR was squashed before being merged into the 4.4 branch (closes #35502).

Discussion
----------

[Messenger] Fix bug when using single route with XML config

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35500
| License       | MIT
| Doc PR        |

When using just a single routing attribute with XML then the sky falls down.

This small change make sure everything works as expected.

Commits
-------

a2a606e [Messenger] Fix bug when using single route with XML config
  • Loading branch information
fabpot committed Jan 29, 2020
2 parents 592a31a + a2a606e commit c573787
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
Expand Up @@ -1193,6 +1193,10 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode)
if (!\is_array($config)) {
return [];
}
// If XML config with only one routing attribute
if (2 === \count($config) && isset($config['message-class']) && isset($config['sender'])) {
$config = [0 => $config];
}

$newConfig = [];
foreach ($config as $k => $v) {
Expand Down
@@ -0,0 +1,12 @@
<?php

$container->loadFromExtension('framework', [
'messenger' => [
'routing' => [
'Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyMessage' => ['amqp'],
],
'transports' => [
'amqp' => 'amqp://localhost/%2f/messages',
],
],
]);
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:messenger>
<framework:routing message-class="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyMessage">
<framework:sender service="amqp" />
</framework:routing>
<framework:transport name="amqp" dsn="amqp://localhost/%2f/messages" />
</framework:messenger>
</framework:config>
</container>
@@ -0,0 +1,7 @@
framework:
messenger:
routing:
'Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyMessage': [amqp]

transports:
amqp: 'amqp://localhost/%2f/messages'
Expand Up @@ -740,6 +740,15 @@ public function testMessengerRouting()
$this->assertEquals(new Reference('messenger.transport.audit'), $sendersLocator->getArgument(0)['messenger.transport.audit']->getValues()[0]);
}

public function testMessengerRoutingSingle()
{
$container = $this->createContainerFromFile('messenger_routing_single');
$senderLocatorDefinition = $container->getDefinition('messenger.senders_locator');

$sendersMapping = $senderLocatorDefinition->getArgument(0);
$this->assertEquals(['amqp'], $sendersMapping[DummyMessage::class]);
}

public function testMessengerTransportConfiguration()
{
$container = $this->createContainerFromFile('messenger_transport');
Expand Down

0 comments on commit c573787

Please sign in to comment.