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