|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Test\Adapter; |
|
4
|
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\Adapter\NexmoMessageAdapter; |
|
6
|
|
|
use IrishDan\NotificationBundle\Message\MessageInterface; |
|
7
|
|
|
|
|
8
|
|
View Code Duplication |
class NexmoMessageAdapterTest extends AdapterTestCase |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
public function setUp() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::setUp(); |
|
13
|
|
|
$parameters = $this->getParametersFromContainer('notification.channel.nexmo.configuration'); |
|
14
|
|
|
$this->adapter = new NexmoMessageAdapter($parameters); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testFormat() |
|
18
|
|
|
{ |
|
19
|
|
|
$message = $this->adapter->format($this->notification); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertValidDispatchData($message); |
|
22
|
|
|
$this->assertMessageDataStructure($message); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertBasicMessageData($message); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testFormatWithTwig() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->setTwig(); |
|
30
|
|
|
$message = $this->adapter->format($this->notification); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertValidDispatchData($message); |
|
33
|
|
|
$this->assertMessageDataStructure($message); |
|
34
|
|
|
|
|
35
|
|
|
$messageData = $message->getMessageData(); |
|
36
|
|
|
$this->assertEquals('New member', $messageData['title']); |
|
37
|
|
|
|
|
38
|
|
|
$message = 'Hello jimBob |
|
39
|
|
|
Notification message for jimBob |
|
40
|
|
|
Sincerely yours, |
|
41
|
|
|
NotificationBundle |
|
42
|
|
|
Sent via nexmo channel.'; |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals($message, $messageData['body']); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
private function assertValidDispatchData(MessageInterface $message) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertEquals('nexmo', $message->getChannel()); |
|
50
|
|
|
|
|
51
|
|
|
$dispatchData = $message->getDispatchData(); |
|
52
|
|
|
$this->assertArrayHasKey('to', $dispatchData); |
|
53
|
|
|
$this->assertArrayHasKey('from', $dispatchData); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals('+44755667788', $dispatchData['to']); |
|
56
|
|
|
$this->assertEquals('JimBob', $dispatchData['from']); |
|
57
|
|
|
} |
|
58
|
|
|
} |
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.