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