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 a7936d2

Browse filesBrowse files
malteschlueterfabpot
authored andcommitted
[Notifier] Check for maximum number of buttons in slack action block
1 parent 2b36487 commit a7936d2
Copy full SHA for a7936d2

File tree

3 files changed

+71
-0
lines changed
Filter options

3 files changed

+71
-0
lines changed

‎src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public function __construct()
2626
*/
2727
public function button(string $text, string $url, string $style = null): self
2828
{
29+
if (25 === \count($this->options['elements'] ?? [])) {
30+
throw new \LogicException('Maximum number of buttons should not exceed 25.');
31+
}
32+
2933
$element = [
3034
'type' => 'button',
3135
'text' => [

‎src/Symfony/Component/Notifier/Bridge/Slack/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* Check for maximum number of buttons in Slack action block
8+
49
5.2.0
510
-----
611

+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\Bridge\Slack\Tests\Block;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackActionsBlock;
16+
17+
final class SlackActionsBlockTest extends TestCase
18+
{
19+
public function testCanBeInstantiated(): void
20+
{
21+
$actions = new SlackActionsBlock();
22+
$actions->button('first button text', 'https://example.org')
23+
->button('second button text', 'https://example.org/slack', 'danger')
24+
;
25+
26+
$this->assertSame([
27+
'type' => 'actions',
28+
'elements' => [
29+
[
30+
'type' => 'button',
31+
'text' => [
32+
'type' => 'plain_text',
33+
'text' => 'first button text',
34+
],
35+
'url' => 'https://example.org',
36+
],
37+
[
38+
'type' => 'button',
39+
'text' => [
40+
'type' => 'plain_text',
41+
'text' => 'second button text',
42+
],
43+
'url' => 'https://example.org/slack',
44+
'style' => 'danger',
45+
],
46+
],
47+
], $actions->toArray());
48+
}
49+
50+
public function testThrowsWhenFieldsLimitReached(): void
51+
{
52+
$section = new SlackActionsBlock();
53+
for ($i = 0; $i < 25; ++$i) {
54+
$section->button($i, $i);
55+
}
56+
57+
$this->expectException(\LogicException::class);
58+
$this->expectExceptionMessage('Maximum number of buttons should not exceed 25.');
59+
60+
$section->button('fail', 'fail');
61+
}
62+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.