Skip to content

Commit 7426084

Browse files
committed
[Notifier] Introduce LengthException
1 parent c82567b commit 7426084

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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\LengthException;
1718
use Symfony\Component\Notifier\Exception\LogicException;
1819
use Symfony\Component\Notifier\Exception\TransportException;
1920
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
@@ -55,7 +56,7 @@ public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
5556
{
5657
$transport = new DiscordTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
5758

58-
$this->expectException(LogicException::class);
59+
$this->expectException(LengthException::class);
5960
$this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.');
6061

6162
$transport->send(new ChatMessage(str_repeat('d', 2001)));

src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackHeaderBlock.php

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

1212
namespace Symfony\Component\Notifier\Bridge\Slack\Block;
1313

14-
use Symfony\Component\Notifier\Exception\LogicException;
14+
use Symfony\Component\Notifier\Exception\LengthException;
1515

1616
/**
1717
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
@@ -26,7 +26,7 @@ final class SlackHeaderBlock extends AbstractSlackBlock
2626
public function __construct(string $text)
2727
{
2828
if (\strlen($text) > self::TEXT_LIMIT) {
29-
throw new LogicException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
29+
throw new LengthException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
3030
}
3131

3232
$this->options = [
@@ -41,7 +41,7 @@ public function __construct(string $text)
4141
public function id(string $id): self
4242
{
4343
if (\strlen($id) > self::ID_LIMIT) {
44-
throw new LogicException(sprintf('Maximum length for the block id is %d characters.', self::ID_LIMIT));
44+
throw new LengthException(sprintf('Maximum length for the block id is %d characters.', self::ID_LIMIT));
4545
}
4646

4747
$this->options['block_id'] = $id;

src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackHeaderBlockTest.php

Lines changed: 3 additions & 3 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\Slack\Block\SlackHeaderBlock;
16-
use Symfony\Component\Notifier\Exception\LogicException;
16+
use Symfony\Component\Notifier\Exception\LengthException;
1717

1818
final class SlackHeaderBlockTest extends TestCase
1919
{
@@ -34,15 +34,15 @@ public function testCanBeInstantiated(): void
3434

3535
public function testThrowsWhenTextExceedsCharacterLimit(): void
3636
{
37-
$this->expectException(LogicException::class);
37+
$this->expectException(LengthException::class);
3838
$this->expectExceptionMessage('Maximum length for the text is 150 characters.');
3939

4040
new SlackHeaderBlock(str_repeat('h', 151));
4141
}
4242

4343
public function testThrowsWhenBlockIdExceedsCharacterLimit(): void
4444
{
45-
$this->expectException(LogicException::class);
45+
$this->expectException(LengthException::class);
4646
$this->expectExceptionMessage('Maximum length for the block id is 255 characters.');
4747

4848
$header = new SlackHeaderBlock('header');
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Exception;
13+
14+
/**
15+
* @author Oskar Stark <oskarstark@googlemail.com>
16+
*
17+
* @experimental in 5.3
18+
*/
19+
class LengthException extends LogicException
20+
{
21+
public function __construct(string $message)
22+
{
23+
parent::__construct($message);
24+
}
25+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy