Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commita7936d2

Browse files
malteschlueterfabpot
authored andcommitted
[Notifier] Check for maximum number of buttons in slack action block
1 parent2b36487 commita7936d2

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public function __construct()
2626
*/
2727
publicfunctionbutton(string$text,string$url,string$style =null):self
2828
{
29+
if (25 ===\count($this->options['elements'] ?? [])) {
30+
thrownew \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‎

Lines 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

Lines 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+
namespaceSymfony\Component\Notifier\Bridge\Slack\Tests\Block;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Notifier\Bridge\Slack\Block\SlackActionsBlock;
16+
17+
finalclass SlackActionsBlockTestextends TestCase
18+
{
19+
publicfunctiontestCanBeInstantiated():void
20+
{
21+
$actions =newSlackActionsBlock();
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+
publicfunctiontestThrowsWhenFieldsLimitReached():void
51+
{
52+
$section =newSlackActionsBlock();
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)

[8]ページ先頭

©2009-2025 Movatter.jp