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 4b97b16

Browse filesBrowse files
committed
bug #39236 [Notifier] Fix slack section block (norkunas)
This PR was merged into the 5.2 branch. Discussion ---------- [Notifier] Fix slack section block | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #... | License | MIT | Doc PR | symfony/symfony-docs#... In SlackSectionBlock fields array is not initialized directly in the constructor so when running tests and trying to add a field to it throws `Undefined index: fields`. Commits ------- 472fa3b Fix checking slack section fields limit
2 parents 5e5796b + 472fa3b commit 4b97b16
Copy full SHA for 4b97b16

File tree

2 files changed

+60
-1
lines changed
Filter options

2 files changed

+60
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackSectionBlock.php
+1-1Lines 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
public function field(string $text, bool $markdown = true): self
4141
{
42-
if (10 === \count($this->options['fields'])) {
42+
if (10 === \count($this->options['fields'] ?? [])) {
4343
throw new \LogicException('Maximum number of fields should not exceed 10.');
4444
}
4545

+59Lines 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+
namespace Symfony\Component\Notifier\Bridge\Slack\Tests\Block;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackImageBlockElement;
16+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
17+
18+
final class SlackSectionBlockTest extends TestCase
19+
{
20+
public function testCanBeInstantiated(): void
21+
{
22+
$section = new SlackSectionBlock();
23+
$section->text('section text');
24+
$section->field('section field');
25+
$section->accessory(new SlackImageBlockElement('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+
public function testThrowsWhenFieldsLimitReached(): void
48+
{
49+
$section = new SlackSectionBlock();
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.