Skip to content

Commit ad284de

Browse files
committed
[Notifier] Add tests for AbstractChannel and ChannelPolicy
1 parent f4332cb commit ad284de

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Notifier\Tests\Channel;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Notifier\Channel\AbstractChannel;
9+
use Symfony\Component\Notifier\Exception\LogicException;
10+
use Symfony\Component\Notifier\Notification\Notification;
11+
use Symfony\Component\Notifier\Recipient\Recipient;
12+
13+
/**
14+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
15+
*/
16+
class AbstractChannelTest extends TestCase
17+
{
18+
public function test_a_channel_cannot_be_constructed_without_transport_and_bus(): void
19+
{
20+
$this->expectException(LogicException::class);
21+
22+
new DummyChannel();
23+
}
24+
}
25+
26+
class DummyChannel extends AbstractChannel
27+
{
28+
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
29+
{
30+
return;
31+
}
32+
33+
public function supports(Notification $notification, Recipient $recipient): bool
34+
{
35+
return false;
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Notifier\Tests\Channel;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Notifier\Channel\ChannelPolicy;
9+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
10+
11+
/**
12+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
13+
*/
14+
class ChannelPolicyTest extends TestCase
15+
{
16+
public function test_cannot_retrieve_channels_using_unavailable_importance(): void
17+
{
18+
$this->expectException(InvalidArgumentException::class);
19+
20+
$channelPolicy = new ChannelPolicy(['urgent' => ['chat']]);
21+
$channelPolicy->getChannels('low');
22+
}
23+
24+
/**
25+
* @dataProvider provideValidPolicies
26+
*/
27+
public function test_can_retrieve_channels(array $policy, string $importance, array $expectedChannels): void
28+
{
29+
$channelPolicy = new ChannelPolicy($policy);
30+
$channels = $channelPolicy->getChannels($importance);
31+
32+
$this->assertSame($expectedChannels, $channels);
33+
}
34+
35+
public function provideValidPolicies(): \Generator
36+
{
37+
yield [['urgent' => ['chat']], 'urgent', ['chat']];
38+
yield [['urgent' => ['chat', 'sms']], 'urgent', ['chat', 'sms']];
39+
yield [['urgent' => ['chat', 'chat/slack', 'sms']], 'urgent', ['chat', 'chat/slack', 'sms']];
40+
}
41+
}

0 commit comments

Comments
 (0)