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
|
|
View Code Duplication |
class MailDataFormatterTest extends FormatterTestCase |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
$this->formatter = new MailDataFormatter( |
16
|
|
|
[ |
17
|
|
|
'default_sender' => '[email protected]', |
18
|
|
|
] |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testFormat() |
23
|
|
|
{ |
24
|
|
|
$message = $this->formatter->format($this->notification); |
25
|
|
|
|
26
|
|
|
$this->assertValidDispatchData($message); |
27
|
|
|
$this->assertMessageDataStructure($message); |
28
|
|
|
|
29
|
|
|
$this->assertBasicMessageData($message); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testFormatWithTwig() |
33
|
|
|
{ |
34
|
|
|
$this->setTwig(); |
35
|
|
|
$message = $this->formatter->format($this->notification); |
36
|
|
|
|
37
|
|
|
$this->assertValidDispatchData($message); |
38
|
|
|
$this->assertMessageDataStructure($message); |
39
|
|
|
|
40
|
|
|
$messageData = $message->getMessageData(); |
41
|
|
|
|
42
|
|
|
$this->assertEquals('New member', $messageData['title']); |
43
|
|
|
$this->assertEquals('Mail notification message for jimBob', $messageData['body']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function assertValidDispatchData(MessageInterface $message) |
47
|
|
|
{ |
48
|
|
|
$this->assertEquals('mail', $message->getChannel()); |
49
|
|
|
|
50
|
|
|
$dispatchData = $message->getDispatchData(); |
51
|
|
|
$this->assertArrayHasKey('to', $dispatchData); |
52
|
|
|
$this->assertArrayHasKey('from', $dispatchData); |
53
|
|
|
|
54
|
|
|
$this->assertEquals('[email protected]', $dispatchData['to']); |
55
|
|
|
$this->assertEquals('[email protected]', $dispatchData['from']); |
56
|
|
|
} |
57
|
|
|
} |
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.