1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Test\Channel; |
4
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\Channel\DirectChannel; |
6
|
|
|
use IrishDan\NotificationBundle\Test\Adapter\DummyAdapter; |
7
|
|
|
use IrishDan\NotificationBundle\Test\NotificationTestCase; |
8
|
|
|
|
9
|
|
|
class DirectChannelTest extends NotificationTestCase |
10
|
|
|
{ |
11
|
|
|
protected $notification; |
12
|
|
|
|
13
|
|
|
public function getChannel($adapter) |
14
|
|
|
{ |
15
|
|
|
$config = [ |
16
|
|
|
'key' => '123abc', |
17
|
|
|
'id' => 123456, |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
$channelName = 'test_channel'; |
21
|
|
|
|
22
|
|
|
return new DirectChannel($config, $channelName, $adapter); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$this->notification = $this->getNotificationWithUser(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testFormat() |
33
|
|
|
{ |
34
|
|
|
$adapter = $this->getMockAdapter(true); |
35
|
|
|
$channel = $this->getChannel($adapter); |
36
|
|
|
|
37
|
|
|
$message = $channel->format($this->notification); |
38
|
|
|
|
39
|
|
|
$this->assertInstanceOf('IrishDan\NotificationBundle\Message\MessageInterface', $message); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testDispatch() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$message = $this->getTestMessage(); |
45
|
|
|
|
46
|
|
|
$adapter = $this->getMockAdapter(false, true); |
47
|
|
|
$channel = $this->getChannel($adapter); |
48
|
|
|
|
49
|
|
|
$dispatched = $channel->dispatch($message); |
50
|
|
|
|
51
|
|
|
$this->assertTrue($dispatched); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function testFormatAndDispatch() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$adapter = $this->getMockAdapter(true, true); |
57
|
|
|
$channel = $this->getChannel($adapter); |
58
|
|
|
|
59
|
|
|
$dispatched = $channel->formatAndDispatch($this->notification); |
60
|
|
|
|
61
|
|
|
$this->assertTrue($dispatched); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testChannelDataIsPassedToAdapter() |
65
|
|
|
{ |
66
|
|
|
$adapter = new DummyAdapter(); |
67
|
|
|
$this->getChannel($adapter); |
68
|
|
|
|
69
|
|
|
$this->assertEquals('test_channel', $adapter->getChannelName()); |
70
|
|
|
$configuration = [ |
71
|
|
|
'key' => '123abc', |
72
|
|
|
'id' => 123456, |
73
|
|
|
]; |
74
|
|
|
$this->assertEquals($configuration, $adapter->getConfiguration()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.