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] Check for maximum number of buttons in slack action block #39300

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 5, 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
[Notifier] Check for maximum number of buttons in slack action block
  • Loading branch information
malteschlueter authored and fabpot committed Dec 5, 2020
commit a7936d2b0e4be96392100b24aa5d2bd4de9ab5e6
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function __construct()
*/
public function button(string $text, string $url, string $style = null): self
{
if (25 === \count($this->options['elements'] ?? [])) {
throw new \LogicException('Maximum number of buttons should not exceed 25.');
}

$element = [
'type' => 'button',
'text' => [
Expand Down
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Notifier/Bridge/Slack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.3.0
-----

* Check for maximum number of buttons in Slack action block

5.2.0
-----

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\SlackActionsBlock;

final class SlackActionsBlockTest extends TestCase
{
public function testCanBeInstantiated(): void
{
$actions = new SlackActionsBlock();
$actions->button('first button text', 'https://example.org')
->button('second button text', 'https://example.org/slack', 'danger')
;

$this->assertSame([
'type' => 'actions',
'elements' => [
[
'type' => 'button',
'text' => [
'type' => 'plain_text',
'text' => 'first button text',
],
'url' => 'https://example.org',
],
[
'type' => 'button',
'text' => [
'type' => 'plain_text',
'text' => 'second button text',
],
'url' => 'https://example.org/slack',
'style' => 'danger',
],
],
], $actions->toArray());
}

public function testThrowsWhenFieldsLimitReached(): void
{
$section = new SlackActionsBlock();
for ($i = 0; $i < 25; ++$i) {
$section->button($i, $i);
}

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

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