8000 [Messenger] Fix routing to multiple fallback transports by valtzu · Pull Request #51508 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Fix routing to multiple fallback transports #51508

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
0