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

[Notifier] Fix slack section block #39236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function text(string $text, bool $markdown = true): self
*/
public function field(string $text, bool $markdown = true): self
{
if (10 === \count($this->options['fields'])) {
if (10 === \count($this->options['fields'] ?? [])) {
throw new \LogicException('Maximum number of fields should not exceed 10.');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Slack\Tests\Block;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackImageBlockElement;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;

final class SlackSectionBlockTest extends TestCase
{
public function testCanBeInstantiated(): void
{
$section = new SlackSectionBlock();
$section->text('section text');
$section->field('section field');
$section->accessory(new SlackImageBlockElement('https://example.com/image.jpg', 'an image'));

$this->assertSame([
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'section text',
],
'fields' => [
[
'type' => 'mrkdwn',
'text' => 'section field',
],
],
'accessory' => [
'type' => 'image',
'image_url' => 'https://example.com/image.jpg',
'alt_text' => 'an image',
],
], $section->toArray());
}

public function testThrowsWhenFieldsLimitReached(): void
{
$section = new SlackSectionBlock();
for ($i = 0; $i < 10; ++$i) {
$section->field($i);
}

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Maximum number of fields should not exceed 10.');

$section->field('fail');
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.