Skip to content
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

[Messenger] Allow passing a string instead of an array in TransportNamesStamp #49270

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
`Symfony\Component\Messenger\Transport\InMemoryTransportFactory` in favor of
`Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport` and
`Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory`
* Allow passing a string instead of an array in `TransportNamesStamp`

6.2
---
Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/Messenger/Stamp/TransportNamesStamp.php
Expand Up @@ -16,11 +16,14 @@
*/
final class TransportNamesStamp implements StampInterface
{
private array $transports;

/**
* @param string[] $transports Transport names to be used for the message
* @param string[]|string $transports Transport names to be used for the message
*/
public function __construct(private array $transports)
public function __construct(array|string $transports)
{
$this->transports = (array) $transports;
}

public function getTransportNames(): array
Expand Down
Expand Up @@ -27,4 +27,13 @@ public function testGetSenders()
$this->assertSame($sender, $stampSenders[$key]);
}
}

public function testGetIndividualSender()
{
$stamp = new TransportNamesStamp('first_transport');
$stampSenders = $stamp->getTransportNames();

$this->assertCount(1, $stampSenders);
$this->assertSame('first_transport', $stampSenders[0]);
}
}