/
NotifierTest.php
54 lines (45 loc) · 1.78 KB
/
NotifierTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @copyright Anton Tuyakhov <atuyakhov@gmail.com>
*/
namespace tuyakhov\notifications\tests;
use tuyakhov\notifications\events\NotificationEvent;
use tuyakhov\notifications\Notifier;
class NotifierTest extends TestCase
{
/**
* @var $notifier Notifier
*/
protected $notifier;
protected function setUp()
{
parent::setUp();
$this->notifier = \Yii::createObject([
'class' => Notifier::className(),
'channels' => [
'mockChannel' => $this->createMock('tuyakhov\notifications\channels\ChannelInterface')
]
]);
}
public function testSend()
{
$notification = $this->createMock('tuyakhov\notifications\NotificationInterface');
$notification->method('broadcastOn')->willReturn(['mockChannel']);
$recipient = $this->createMock('tuyakhov\notifications\NotifiableInterface');
$recipient->method('shouldReceiveNotification')->willReturn(true);
$recipient->method('viaChannels')->willReturn(['mockChannel']);
$this->notifier->channels['mockChannel']
->expects($this->once())
->method('send')
->with($recipient, $notification);
$eventRaised = null;
$this->notifier->on(Notifier::EVENT_AFTER_SEND, function(NotificationEvent $event) use (&$eventRaised) {
$eventRaised = $event;
});
$this->notifier->send($recipient, $notification);
$this->assertNotEmpty($eventRaised);
$this->assertInstanceOf('tuyakhov\notifications\NotificationInterface', $eventRaised->notification);
$this->assertInstanceOf('tuyakhov\notifications\NotifiableInterface', $eventRaised->recipient);
$this->assertEquals('mockChannel', $eventRaised->channel);
}
}