8000 [Notifier] UnsupportedMessageTypeException for notifier transports · symfony/symfony@312920d · GitHub
[go: up one dir, main page]

Skip to content

Commit 312920d

Browse files
committed
[Notifier] UnsupportedMessageTypeException for notifier transports
1 parent 979a539 commit 312920d

28 files changed

+95
-46
lines changed

src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Notifier\Exception\LogicException;
1515
use Symfony\Component\Notifier\Exception\TransportException;
16+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1617
use Symfony\Component\Notifier\Message\ChatMessage;
1718
use Symfony\Component\Notifier\Message\MessageInterface;
1819
use Symfony\Component\Notifier\Message\SentMessage;
@@ -59,7 +60,7 @@ public function supports(MessageInterface $message): bool
5960
protected function doSend(MessageInterface $message): SentMessage
6061
{
6162
if (!$message instanceof ChatMessage) {
62-
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
63+
throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
6364
}
6465

6566
$messageOptions = $message->getOptions();

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
1616
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport;
17-
use Symfony\Component\Notifier\Exception\LogicException;
1817
use Symfony\Component\Notifier\Exception\TransportException;
18+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1919
use Symfony\Component\Notifier\Message\ChatMessage;
2020
use Symfony\Component\Notifier\Message\MessageInterface;
2121
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -43,9 +43,10 @@ public function testSupportsChatMessage()
4343

4444
public function testSendNonChatMessageThrows()
4545
{
46-
$this->expectException(LogicException::class);
4746
$transport = new DiscordTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
4847

48+
$this->expectException(UnsupportedMessageTypeException::class);
49+
4950
$transport->send($this->createMock(MessageInterface::class));
5051
}
5152

src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\Component\HttpClient\Exception\JsonException;
1515
use Symfony\Component\HttpClient\Exception\TransportException as HttpClientTransportException;
16-
use Symfony\Component\Notifier\Exception\LogicException;
1716
use Symfony\Component\Notifier\Exception\TransportException;
17+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1818
use Symfony\Component\Notifier\Message\MessageInterface;
1919
use Symfony\Component\Notifier\Message\SentMessage;
2020
use Symfony\Component\Notifier\Message\SmsMessage;
@@ -55,7 +55,7 @@ public function supports(MessageInterface $message): bool
5555
protected function doSend(MessageInterface $message): SentMessage
5656
{
5757
if (!$message instanceof SmsMessage) {
58-
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
58+
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
5959
}
6060

6161
$messageData = [

src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
1616
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
17-
use Symfony\Component\Notifier\Exception\LogicException;
1817
use Symfony\Component\Notifier\Exception\TransportException;
18+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1919
use Symfony\Component\Notifier\Message\MessageInterface;
2020
use Symfony\Component\Notifier\Message\SmsMessage;
2121
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -43,7 +43,8 @@ public function testSendNonSmsMessageThrows(): void
4343
{
4444
$transport = new EsendexTransport('testToken', 'accountReference', 'from', $this->createMock(HttpClientInterface::class));
4545

46-
$this->expectException(LogicException::class);
46+
$this->expectException(UnsupportedMessageTypeException::class);
47+
4748
$transport->send($this->createMock(MessageInterface::class));
4849
}
4950

src/Symfony/Component/Notifier/Bridge/Firebase/FirebaseTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Notifier\Bridge\Firebase;
1313

1414
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
15-
use Symfony\Component\Notifier\Exception\LogicException;
1615
use Symfony\Component\Notifier\Exception\TransportException;
16+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1717
use Symfony\Component\Notifier\Message\ChatMessage;
1818
use Symfony\Component\Notifier\Message\MessageInterface;
1919
use Symfony\Component\Notifier\Message\SentMessage;
@@ -54,7 +54,7 @@ public function supports(MessageInterface $message): bool
5454
protected function doSend(MessageInterface $message): SentMessage
5555
{
5656
if (!$message instanceof ChatMessage) {
57-
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
57+
throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
5858
}
5959

6060
$endpoint = sprintf('https://%s', $this->getEndpoint());

src/Symfony/Component/Notifier/Bridge/FreeMobile/FreeMobileTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\FreeMobile;
1313

14-
use Symfony\Component\Notifier\Exception\LogicException;
1514
use Symfony\Component\Notifier\Exception\TransportException;
15+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1616
use Symfony\Component\Notifier\Message\MessageInterface;
1717
use Symfony\Component\Notifier\Message\SentMessage;
1818
use Symfony\Component\Notifier\Message\SmsMessage;
@@ -55,7 +55,7 @@ public function supports(MessageInterface $message): bool
5555
protected function doSend(MessageInterface $message): SentMessage
5656
{
5757
if (!$this->supports($message)) {
58-
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given) and configured with your phone number.', __CLASS__, SmsMessage::class, \get_class($message)));
58+
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
5959
}
6060

6161
$response = $this->client->request('POST', $this->getEndpoint(), [

src/Symfony/Component/Notifier/Bridge/FreeMobile/Tests/FreeMobileTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport;
16-
use Symfony\Component\Notifier\Exception\LogicException;
16+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1717
use Symfony\Component\Notifier\Message\MessageInterface;
1818
use Symfony\Component\Notifier\Message\SmsMessage;
1919
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -46,7 +46,7 @@ public function testSendNonSmsMessageThrowsException(): void
4646
{
4747
$transport = $this->getTransport('0611223344');
4848

49-
$this->expectException(LogicException::class);
49+
$this->expectException(UnsupportedMessageTypeException::class);
5050

5151
$transport->send(new SmsMessage('0699887766', 'Hello!'));
5252
}

src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatTransport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpClient\Exception\JsonException;
1515
use Symfony\Component\Notifier\Exception\LogicException;
1616
use Symfony\Component\Notifier\Exception\TransportException;
17+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1718
use Symfony\Component\Notifier\Message\ChatMessage;
1819
use Symfony\Component\Notifier\Message\MessageInterface;
1920
use Symfony\Component\Notifier\Message\SentMessage;
@@ -89,7 +90,7 @@ public function supports(MessageInterface $message): bool
8990
protected function doSend(MessageInterface $message): SentMessage
9091
{
9192
if (!$message instanceof ChatMessage) {
92-
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, \get_class($message)));
93+
throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
9394
}
9495
if ($message->getOptions() && !$message->getOptions() instanceof GoogleChatOptions) {
9596
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, GoogleChatOptions::class));

src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatTransportTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransport;
1818
use Symfony\Component\Notifier\Exception\LogicException;
1919
use Symfony\Component\Notifier\Exception\TransportException;
20+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
2021
use Symfony\Component\Notifier\Message\ChatMessage;
2122
use Symfony\Component\Notifier\Message\MessageInterface;
2223
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
@@ -44,10 +45,10 @@ public function testSupportsChatMessage(): void
4445

4546
public function testSendNonChatMessageThrows(): void
4647
{
47-
$this->expectException(LogicException::class);
48-
4948
$transport = new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $this->createMock(HttpClientInterface::class));
5049

50+
$this->expectException(UnsupportedMessageTypeException::class);
51+
5152
$transport->send($this->createMock(MessageInterface::class));
5253
}
5354

src/Symfony/Component/Notifier/Bridge/Infobip/InfobipTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Infobip;
1313

14-
use Symfony\Component\Notifier\Exception\LogicException;
1514
use Symfony\Component\Notifier\Exception\TransportException;
15+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1616
use Symfony\Component\Notifier\Message\MessageInterface;
1717
use Symfony\Component\Notifier\Message\SentMessage;
1818
use Symfony\Component\Notifier\Message\SmsMessage;
@@ -52,7 +52,7 @@ public function supports(MessageInterface $message): bool
5252
protected function doSend(MessageInterface $message): SentMessage
5353
{
5454
if (!$message instanceof SmsMessage) {
55-
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
55+
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
5656
}
5757

5858
$endpoint = sprintf('https://%s/sms/2/text/advanced', $this->getEndpoint());

0 commit comments

Comments
 (0)
0