/
SlackChannelTest.php
48 lines (40 loc) · 1.45 KB
/
SlackChannelTest.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
<?php
/**
* @copyright Anton Tuyakhov <atuyakhov@gmail.com>
*/
namespace tuyakhov\notifications\tests;
use tuyakhov\notifications\channels\SlackChannel;
use tuyakhov\notifications\messages\SlackMessage;
use yii\httpclient\Client;
class SlackChannelTest
{
public function testSend()
{
$recipient = $this->createMock('tuyakhov\notifications\NotifiableInterface');
$recipient->expects($this->once())
->method('routeNotificationFor')
->with('slack')
->willReturn('https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX');
$client = $this->createMock(Client::className());
$client->expects($this->once())
->method('send');
$client->method('createRequest')
->willReturn(\Yii::createObject([
'class' => Request::className(),
'client' => $client
]));
$channel = \Yii::createObject([
'class' => SlackChannel::className(),
'httpClient' => $client
]);
$notification = $this->createMock('tuyakhov\notifications\NotificationInterface');
$notification->expects($this->once())
->method('exportFor')
->with('slack')
->willReturn(\Yii::createObject([
'class' => SlackMessage::className(),
'body' => 'Test message body',
]));
$channel->send($recipient, $notification);
}
}