8000 Throw error if maximum block limit is reached for slack message options · symfony/symfony@4adb17d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4adb17d

Browse files
committed
Throw error if maximum block limit is reached for slack message options
1 parent b5d4b33 commit 4adb17d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Symfony/Component/Notifier/Bridge/Slack/SlackOptions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public function asUser(bool $bool): self
9797
*/
9898
public function block(SlackBlockInterface $block): self
9999
{
100+
if (50 === \count($this->options['blocks'] ?? [])) {
101+
throw new \LogicException('Maximum number of blocks should not exceed 50.');
102+
}
103+
100104
$this->options['blocks'][] = $block->toArray();
101105

102106
return $this;

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackOptionsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1616
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
17+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
1718
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
1819
use Symfony\Component\Notifier\Notification\Notification;
1920

@@ -187,4 +188,17 @@ public function fromNotificationProvider(): iterable
187188
(new Notification($subject))->emoji($emoji)->content($content),
188189
];
189190
}
191+
192+
public function testThrowsWhenBlocksLimitReached()
193+
{
194+
$options = new SlackOptions();
195+
for ($i = 0; $i < 50; ++$i) {
196+
$options->block(new SlackSectionBlock());
197+
}
198+
199+
$this->expectException(\LogicException::class);
200+
$this->expectExceptionMessage('Maximum number of blocks should not exceed 50.');
201+
202+
$options->block(new SlackSectionBlock());
203+
}
190204
}

0 commit comments

Comments
 (0)
0