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

Commit472fa3b

Browse files
committed
Fix checking slack section fields limit
1 parent6440b70 commit472fa3b

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function text(string $text, bool $markdown = true): self
3939
*/
4040
publicfunctionfield(string$text,bool$markdown =true):self
4141
{
42-
if (10 ===\count($this->options['fields'])) {
42+
if (10 ===\count($this->options['fields'] ?? [])) {
4343
thrownew \LogicException('Maximum number of fields should not exceed 10.');
4444
}
4545

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\SlackImageBlockElement;
16+
useSymfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
17+
18+
finalclass SlackSectionBlockTestextends TestCase
19+
{
20+
publicfunctiontestCanBeInstantiated():void
21+
{
22+
$section =newSlackSectionBlock();
23+
$section->text('section text');
24+
$section->field('section field');
25+
$section->accessory(newSlackImageBlockElement('https://example.com/image.jpg','an image'));
26+
27+
$this->assertSame([
28+
'type' =>'section',
29+
'text' => [
30+
'type' =>'mrkdwn',
31+
'text' =>'section text',
32+
],
33+
'fields' => [
34+
[
35+
'type' =>'mrkdwn',
36+
'text' =>'section field',
37+
],
38+
],
39+
'accessory' => [
40+
'type' =>'image',
41+
'image_url' =>'https://example.com/image.jpg',
42+
'alt_text' =>'an image',
43+
],
44+
],$section->toArray());
45+
}
46+
47+
publicfunctiontestThrowsWhenFieldsLimitReached():void
48+
{
49+
$section =newSlackSectionBlock();
50+
for ($i =0;$i <10; ++$i) {
51+
$section->field($i);
52+
}
53+
54+
$this->expectException(\LogicException::class);
55+
$this->expectExceptionMessage('Maximum number of fields should not exceed 10.');
56+
57+
$section->field('fail');
58+
}
59+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp