Skip to content

Commit 76f2433

Browse files
committed
Fix routing to multiple fallback transports
1 parent 70bb680 commit 76f2433

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Sender/SendersLocatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ public function testSendersMapWithFallback()
5656
{
5757
$firstSender = $this->createMock(SenderInterface::class);
5858
$secondSender = $this->createMock(SenderInterface::class);
59+
$thirdSender = $this->createMock(SenderInterface::class);
5960
$sendersLocator = $this->createContainer([
6061
'first' => $firstSender,
6162
'second' => $secondSender,
63+
'third' => $thirdSender,
6264
]);
6365
$locator = new SendersLocator([
6466
DummyMessage::class => ['first'],
65-
'*' => ['second'],
67+
'*' => ['second', 'third'],
6668
], $sendersLocator);
6769

6870
$this->assertSame(['first' => $firstSender], iterator_to_array($locator->getSenders(new Envelope(new DummyMessage('a')))), 'Unexpected senders for configured message');
69-
$this->assertSame(['second' => $secondSender], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))), 'Unexpected senders for unconfigured message');
71+
$this->assertSame(['second' => $secondSender, 'third' => $thirdSender], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))), 'Unexpected senders for unconfigured message');
7072
}
7173

7274
private function createContainer(array $senders): ContainerInterface

src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public function getSenders(Envelope $envelope): iterable
5050
$seen = [];
5151

5252
foreach (HandlersLocator::listTypes($envelope) as $type) {
53-
foreach ($this->sendersMap[$type] ?? [] as $senderAlias) {
54-
if (str_ends_with($type, '*') && $seen) {
55-
// the '*' acts as a fallback, if other senders already matched
56-
// with previous types, skip the senders bound to the fallback
57-
continue;
58-
}
53+
if (str_ends_with($type, '*') && $seen) {
54+
// the '*' acts as a fallback, if other senders already matched
55+
// with previous types, skip the senders bound to the fallback
56+
continue;
57+
}
5958

59+
foreach ($this->sendersMap[$type] ?? [] as $senderAlias) {
6060
if (!\in_array($senderAlias, $seen, true)) {
6161
$seen[] = $senderAlias;
6262

0 commit comments

Comments
 (0)