Completed
Push — master ( 0e7751...1494d2 )
by dan
02:09
created

MailMessageAdapterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testFormat() 0 9 1
A testFormatWithTwig() 0 19 1
A assertValidDispatchData() 0 11 1
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, $parameters);
20
    }
21
22
    public function testFormat()
23
    {
24
        $message = $this->adapter->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->adapter->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
        $message = 'Hello jimBob
44
Notification message for jimBob
45
Sincerely yours,
46
NotificationBundle
47
Sent via mail channel.';
48
49
        $this->assertEquals($message, $messageData['body']);
50
    }
51
52
    private function assertValidDispatchData(MessageInterface $message)
53
    {
54
        $this->assertEquals('mail', $message->getChannel());
55
56
        $dispatchData = $message->getDispatchData();
57
        $this->assertArrayHasKey('to', $dispatchData);
58
        $this->assertArrayHasKey('from', $dispatchData);
59
60
        $this->assertEquals('[email protected]', $dispatchData['to']);
61
        $this->assertEquals('[email protected]', $dispatchData['from']);
62
    }
63
}