Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Do not return fallback senders when other senders were already found #48121

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
merged 1 commit into from
Dec 21, 2022
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 @@ -52,6 +52,23 @@ public function testItReturnsTheSenderBasedOnTransportNamesStamp()
$this->assertSame([], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))));
}

public function testSendersMapWithFallback()
{
$firstSender = $this->createMock(SenderInterface::class);
$secondSender = $this->createMock(SenderInterface::class);
$sendersLocator = $this->createContainer([
'first' => $firstSender,
'second' => $secondSender,
]);
$locator = new SendersLocator([
DummyMessage::class => ['first'],
'*' => ['second'],
], $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');
}

private function createContainer(array $senders): ContainerInterface
{
$container = $this->createMock(ContainerInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function getSenders(Envelope $envelope): iterable

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 (!\in_array($senderAlias, $seen, true)) {
$seen[] = $senderAlias;

Expand Down