|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
|
16 | 16 | use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
|
| 17 | +use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock; |
17 | 18 | use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
|
| 19 | +use Symfony\Component\Notifier\Exception\LogicException; |
18 | 20 | use Symfony\Component\Notifier\Notification\Notification;
|
19 | 21 |
|
20 | 22 | /**
|
@@ -187,4 +189,42 @@ public function fromNotificationProvider(): iterable
|
187 | 189 | (new Notification($subject))->emoji($emoji)->content($content),
|
188 | 190 | ];
|
189 | 191 | }
|
| 192 | + |
| 193 | + public function testConstructWithMaximumBlocks() |
| 194 | + { |
| 195 | + $options = new SlackOptions(['blocks' => array_map(static function () { return ['type' => 'divider']; }, range(0, 49))]); |
| 196 | + |
| 197 | + $this->assertCount(50, $options->toArray()['blocks']); |
| 198 | + } |
| 199 | + |
| 200 | + public function testConstructThrowsWithTooManyBlocks() |
| 201 | + { |
| 202 | + $this->expectException(LogicException::class); |
| 203 | + $this->expectExceptionMessage('Maximum number of "blocks" has been reached (50).'); |
| 204 | + |
| 205 | + new SlackOptions(['blocks' => array_map(static function () { return ['type' => 'divider']; }, range(0, 50))]); |
| 206 | + } |
| 207 | + |
| 208 | + public function testAddMaximumBlocks() |
| 209 | + { |
| 210 | + $options = new SlackOptions(); |
| 211 | + for ($i = 0; $i < 50; ++$i) { |
| 212 | + $options->block(new SlackSectionBlock()); |
| 213 | + } |
| 214 | + |
| 215 | + $this->assertCount(50, $options->toArray()['blocks']); |
| 216 | + } |
| 217 | + |
| 218 | + public function testThrowsWhenBlocksLimitReached() |
| 219 | + { |
| 220 | + $options = new SlackOptions(); |
| 221 | + for ($i = 0; $i < 50; ++$i) { |
| 222 | + $options->block(new SlackSectionBlock()); |
| 223 | + } |
| 224 | + |
| 225 | + $this->expectException(LogicException::class); |
| 226 | + $this->expectExceptionMessage('Maximum number of "blocks" has been reached (50).'); |
| 227 | + |
| 228 | + $options->block(new SlackSectionBlock()); |
| 229 | + } |
190 | 230 | }
|
0 commit comments