From 01623391f634f991317e8f8e53d5e3732664e2b3 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 11 Dec 2020 10:11:18 +0100 Subject: [PATCH] [Notifier][Discord] Fix exception message + test --- .../Notifier/Bridge/Discord/DiscordTransport.php | 2 +- .../Bridge/Discord/Tests/DiscordTransportTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php b/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php index 012d5acde9a76..afa98f77d6b3d 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php @@ -66,7 +66,7 @@ protected function doSend(MessageInterface $message): SentMessage $content = $message->getSubject(); if (\strlen($content) > 2000) { - throw new LogicException(sprintf('The subject length of "%s" transport must be less than 2000 characters.', __CLASS__)); + throw new LogicException('The subject length of a Discord message must not exceed 2000 characters.'); } $endpoint = sprintf('https://%s/api/webhooks/%s/%s', $this->getEndpoint(), $this->webhookId, $this->token); diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php index 097b1ad25caf8..154a795530fbf 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php @@ -49,6 +49,16 @@ public function testSendNonChatMessageThrows() $transport->send($this->createMock(MessageInterface::class)); } + public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException() + { + $transport = new DiscordTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class)); + + $this->expectException(LogicException::class); + $this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.'); + + $transport->send(new ChatMessage(str_repeat('d', 2001))); + } + public function testSendWithErrorResponseThrows() { $this->expectException(TransportException::class);