Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4adb17d

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

File tree

2 files changed

+18
-0
lines changed
Filter options

2 files changed

+18
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/SlackOptions.php
+4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackOptionsTest.php
+14Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.