Skip to content

Commit 066990b

Browse files
committed
Send message to the first supporting transport
1 parent 05caa0a commit 066990b

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/Symfony/Component/Notifier/Tests/Transport/TransportsTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class TransportsTest extends TestCase
2222
{
23-
public function test_send_to_transport_defined_by_message(): void
23+
public function testSendToTransportDefinedByMessage(): void
2424
{
2525
$transports = new Transports([
2626
'one' => $one = $this->createMock(TransportInterface::class),
@@ -35,31 +35,25 @@ public function test_send_to_transport_defined_by_message(): void
3535
$transports->send($message);
3636
}
3737

38-
public function test_send_to_all_supported_transports_if_message_does_not_define_a_transport(): void
38+
public function testSendToFirstSupportedTransportIfMessageDoesNotDefineATransport(): void
3939
{
4040
$transports = new Transports([
4141
'one' => $one = $this->createMock(TransportInterface::class),
4242
'two' => $two = $this->createMock(TransportInterface::class),
43-
'three' => $three = $this->createMock(TransportInterface::class),
44-
'four' => $four = $this->createMock(TransportInterface::class),
4543
]);
4644

4745
$message = new ChatMessage('subject');
4846

4947
$one->method('supports')->with($message)->willReturn(false);
5048
$two->method('supports')->with($message)->willReturn(true);
51-
$three->method('supports')->with($message)->willReturn(false);
52-
$four->method('supports')->with($message)->willReturn(true);
5349

5450
$one->expects($this->never())->method('send');
5551
$two->expects($this->once())->method('send');
56-
$three->expects($this->never())->method('send');
57-
$four->expects($this->once())->method('send');
5852

5953
$transports->send($message);
6054
}
6155

62-
public function test_throw_exception_if_no_supported_transport_was_found(): void
56+
public function testThrowExceptionIfNoSupportedTransportWasFound(): void
6357
{
6458
$transports = new Transports([
6559
'one' => $one = $this->createMock(TransportInterface::class),
@@ -75,7 +69,7 @@ public function test_throw_exception_if_no_supported_transport_was_found(): void
7569
$transports->send($message);
7670
}
7771

78-
public function test_throw_exception_if_transport_defined_by_message_is_not_supported(): void
72+
public function testThrowExceptionIfTransportDefinedByMessageIsNotSupported(): void
7973
{
8074
$transports = new Transports([
8175
'one' => $one = $this->createMock(TransportInterface::class),
@@ -94,7 +88,7 @@ public function test_throw_exception_if_transport_defined_by_message_is_not_supp
9488
$transports->send($message);
9589
}
9690

97-
public function test_throw_exception_if_transport_defined_by_message_does_not_exist()
91+
public function testThrowExceptionIfTransportDefinedByMessageDoesNotExist()
9892
{
9993
$transports = new Transports([
10094
'one' => $one = $this->createMock(TransportInterface::class),

src/Symfony/Component/Notifier/Transport/Transports.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,14 @@ public function supports(MessageInterface $message): bool
5454
public function send(MessageInterface $message): void
5555
{
5656
if (!$transport = $message->getTransport()) {
57-
$supportedTransportsCount = 0;
5857
foreach ($this->transports as $transport) {
5958
if ($transport->supports($message)) {
6059
$transport->send($message);
61-
++$supportedTransportsCount;
60+
return;
6261
}
6362
}
6463

65-
if (0 === $supportedTransportsCount) {
66-
throw new LogicException(sprintf('None of the available transports support the given message (available transports: "%s").', implode('", "', array_keys($this->transports))));
67-
}
68-
69-
return;
64+
throw new LogicException(sprintf('None of the available transports support the given message (available transports: "%s").', implode('", "', array_keys($this->transports))));
7065
}
7166

7267
if (!isset($this->transports[$transport])) {

0 commit comments

Comments
 (0)