Skip to content

Commit 02e72c2

Browse files
committed
[Notifier] Add tests for AbstractChannel and ChannelPolicy
1 parent d41f424 commit 02e72c2

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

Tests/Channel/AbstractChannelTest.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\Tests\Channel;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Channel\AbstractChannel;
16+
use Symfony\Component\Notifier\Exception\LogicException;
17+
use Symfony\Component\Notifier\Notification\Notification;
18+
use Symfony\Component\Notifier\Recipient\Recipient;
19+
20+
/**
21+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
22+
*/
23+
class AbstractChannelTest extends TestCase
24+
{
25+
public function testChannelCannotBeConstructedWithoutTransportAndBus()
26+
{
27+
$this->expectException(LogicException::class);
28+
29+
new DummyChannel();
30+
}
31+
}
32+
33+
class DummyChannel extends AbstractChannel
34+
{
35+
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
36+
{
37+
return;
38+
}
39+
40+
public function supports(Notification $notification, Recipient $recipient): bool
41+
{
42+
return false;
43+
}
44+
}

Tests/Channel/ChannelPolicyTest.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\Tests\Channel;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Channel\ChannelPolicy;
16+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
17+
18+
/**
19+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
20+
*/
21+
class ChannelPolicyTest extends TestCase
22+
{
23+
public function testCannotRetrieveChannelsUsingUnavailableImportance()
24+
{
25+
$this->expectException(InvalidArgumentException::class);
26+
27+
$channelPolicy = new ChannelPolicy(['urgent' => ['chat']]);
28+
$channelPolicy->getChannels('low');
29+
}
30+
31+
/**
32+
* @dataProvider provideValidPolicies
33+
*/
34+
public function testCanRetrieveChannels(array $policy, string $importance, array $expectedChannels)
35+
{
36+
$channelPolicy = new ChannelPolicy($policy);
37+
$channels = $channelPolicy->getChannels($importance);
38+
39+
$this->assertSame($expectedChannels, $channels);
40+
}
41+
42+
public function provideValidPolicies(): \Generator
43+
{
44+
yield [['urgent' => ['chat']], 'urgent', ['chat']];
45+
yield [['urgent' => ['chat', 'sms']], 'urgent', ['chat', 'sms']];
46+
yield [['urgent' => ['chat', 'chat/slack', 'sms']], 'urgent', ['chat', 'chat/slack', 'sms']];
47+
}
48+
}

0 commit comments

Comments
 (0)