diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Sender/SendersLocatorTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Sender/SendersLocatorTest.php index 4d9697eeaccc1..6b005cfd86e27 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Sender/SendersLocatorTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Sender/SendersLocatorTest.php @@ -56,17 +56,19 @@ public function testSendersMapWithFallback() { $firstSender = $this->createMock(SenderInterface::class); $secondSender = $this->createMock(SenderInterface::class); + $thirdSender = $this->createMock(SenderInterface::class); $sendersLocator = $this->createContainer([ 'first' => $firstSender, 'second' => $secondSender, + 'third' => $thirdSender, ]); $locator = new SendersLocator([ DummyMessage::class => ['first'], - '*' => ['second'], + '*' => ['second', 'third'], ], $sendersLocator); $this->assertSame(['first' => $firstSender], iterator_to_array($locator->getSenders(new Envelope(new DummyMessage('a')))), 'Unexpected senders for configured message'); - $this->assertSame(['second' => $secondSender], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))), 'Unexpected senders for unconfigured message'); + $this->assertSame(['second' => $secondSender, 'third' => $thirdSender], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))), 'Unexpected senders for unconfigured message'); } private function createContainer(array $senders): ContainerInterface diff --git a/src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php b/src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php index 3420a6cc6043a..f8308ada3e2d2 100644 --- a/src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php +++ b/src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php @@ -50,13 +50,13 @@ public function getSenders(Envelope $envelope): iterable $seen = []; foreach (HandlersLocator::listTypes($envelope) as $type) { - foreach ($this->sendersMap[$type] ?? [] as $senderAlias) { - if (str_ends_with($type, '*') && $seen) { - // the '*' acts as a fallback, if other senders already matched - // with previous types, skip the senders bound to the fallback - continue; - } + if (str_ends_with($type, '*') && $seen) { + // the '*' acts as a fallback, if other senders already matched + // with previous types, skip the senders bound to the fallback + continue; + } + foreach ($this->sendersMap[$type] ?? [] as $senderAlias) { if (!\in_array($senderAlias, $seen, true)) { $seen[] = $senderAlias;