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