Completed
Push — master ( 50fbec...218e95 )
by dan
08:09
created

MailDataFormatterTest::testFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 15
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
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
    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
32
        $messageData = $message->getMessageData();
33
        $this->assertArrayHasKey('title', $messageData);
34
        $this->assertArrayHasKey('body', $messageData);
35
36
        $this->assertEquals('New member', $messageData['title']);
37
        $this->assertEquals('A new member has just joined', $messageData['body']);
38
    }
39
40
    public function testFormatWithTwig()
41
    {
42
        $twig = $this->getService('twig');
43
        $this->formatter->setTemplating($twig);
44
        $message = $this->formatter->format($this->notification);
45
46
        $this->assertValidDispatchData($message);
47
48
        // @TODO:
49
    }
50
51
    public function assertValidDispatchData(MessageInterface $message)
52
    {
53
        $this->assertEquals('mail', $message->getChannel());
54
55
        $dispatchData = $message->getDispatchData();
56
        $this->assertArrayHasKey('to', $dispatchData);
57
        $this->assertArrayHasKey('from', $dispatchData);
58
59
        $this->assertEquals('[email protected]', $dispatchData['to']);
60
        $this->assertEquals('[email protected]', $dispatchData['from']);
61
    }
62
}