Completed
Push — master ( 218e95...e3a73f )
by dan
02:12
created

assertMessageDataStructure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
}