1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Test\Formatter; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use IrishDan\NotificationBundle\Formatter\MailDataFormatter; |
7
|
|
|
use IrishDan\NotificationBundle\Message\MessageInterface; |
8
|
|
|
|
9
|
|
|
class MailDataFormatterTest extends FormatterTestCase |
10
|
|
|
{ |
11
|
|
|
protected $formatter; |
12
|
|
|
|
13
|
|
|
public function setUp() |
14
|
|
|
{ |
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
$this->formatter = new MailDataFormatter( |
18
|
|
|
[ |
19
|
|
|
'default_sender' => '[email protected]', |
20
|
|
|
] |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
View Code Duplication |
public function testFormat() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$message = $this->formatter->format($this->notification); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf('IrishDan\NotificationBundle\Message\MessageInterface', $message); |
29
|
|
|
|
30
|
|
|
$this->assertValidDispatchData($message); |
31
|
|
|
$this->assertMessageDataStructure($message); |
32
|
|
|
|
33
|
|
|
$messageData = $message->getMessageData(); |
34
|
|
|
$this->assertEquals('New member', $messageData['title']); |
35
|
|
|
$this->assertEquals('A new member has just joined', $messageData['body']); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function testFormatWithTwig() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$twig = $this->getService('twig'); |
41
|
|
|
$this->formatter->setTemplating($twig); |
42
|
|
|
$message = $this->formatter->format($this->notification); |
43
|
|
|
|
44
|
|
|
$this->assertValidDispatchData($message); |
45
|
|
|
$this->assertMessageDataStructure($message); |
46
|
|
|
|
47
|
|
|
$messageData = $message->getMessageData(); |
48
|
|
|
|
49
|
|
|
$this->assertEquals('New member', $messageData['title']); |
50
|
|
|
$this->assertEquals('Mail notification message for jimBob', $messageData['body']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function assertMessageDataStructure(MessageInterface $message) |
54
|
|
|
{ |
55
|
|
|
$messageData = $message->getMessageData(); |
56
|
|
|
$this->assertArrayHasKey('title', $messageData); |
57
|
|
|
$this->assertArrayHasKey('body', $messageData); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function assertValidDispatchData(MessageInterface $message) |
61
|
|
|
{ |
62
|
|
|
$this->assertEquals('mail', $message->getChannel()); |
63
|
|
|
|
64
|
|
|
$dispatchData = $message->getDispatchData(); |
65
|
|
|
$this->assertArrayHasKey('to', $dispatchData); |
66
|
|
|
$this->assertArrayHasKey('from', $dispatchData); |
67
|
|
|
|
68
|
|
|
$this->assertEquals('[email protected]', $dispatchData['to']); |
69
|
|
|
$this->assertEquals('[email protected]', $dispatchData['from']); |
70
|
|
|
} |
71
|
|
|
} |
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.