|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hautzi\SystemMailBundle\Tests\SystemMailer; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\MailDefinition\ParserInterface; |
|
7
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\MailDefinition\ProviderInterface; |
|
8
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\Mailer\MailerInterface; |
|
9
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\ParsedMessage; |
|
10
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\SystemMailer; |
|
11
|
|
|
|
|
12
|
|
|
class SystemMailerTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
protected $fixture; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var ProviderInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $provider; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ParserInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $parser; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var MailerInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $mailer; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function testSendWithoutDefaults() |
|
31
|
|
|
{ |
|
32
|
|
|
$fixture = $this->createFixture('de'); |
|
33
|
|
|
|
|
34
|
|
|
$parsedMessage = $this->prophesize(ParsedMessage::class)->reveal(); |
|
35
|
|
|
|
|
36
|
|
|
$this->provider->fetchMailDefinition('App:test', ['param1' => 'yay!'])->willReturn('<email></email>')->shouldBeCalled(); |
|
|
|
|
|
|
37
|
|
|
$this->parser->parseMailDefinition('<email></email>', 'de')->willReturn($parsedMessage)->shouldBeCalled(); |
|
|
|
|
|
|
38
|
|
|
$this->mailer->send($parsedMessage, null)->shouldBeCalled(); |
|
39
|
|
|
|
|
40
|
|
|
$fixture->send('App:test', ['param1' => 'yay!']); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function testSendDefaultsArePopulated() |
|
45
|
|
|
{ |
|
46
|
|
|
$fixture = $this->createFixture('de', [ |
|
47
|
|
|
'subject' => '_1', |
|
48
|
|
|
'replyTo' => '_2', |
|
49
|
|
|
'from' => [ |
|
50
|
|
|
'email' => '_3', |
|
51
|
|
|
'name' => '_4', |
|
52
|
|
|
], |
|
53
|
|
|
'to' => [ |
|
54
|
|
|
'email' => '_5', |
|
55
|
|
|
'name' => '_6', |
|
56
|
|
|
], |
|
57
|
|
|
'cc' => [ |
|
58
|
|
|
'email' => '_7', |
|
59
|
|
|
'name' => '_8', |
|
60
|
|
|
], |
|
61
|
|
|
'bcc' => [ |
|
62
|
|
|
'email' => '_9', |
|
63
|
|
|
'name' => '_10', |
|
64
|
|
|
] |
|
65
|
|
|
]); |
|
66
|
|
|
|
|
67
|
|
|
$parsedMessage = $this->prophesize(ParsedMessage::class); |
|
68
|
|
|
$parsedMessage->getSubject()->willReturn(null); |
|
69
|
|
|
$parsedMessage->setSubject('_1')->shouldBeCalled(); |
|
70
|
|
|
$parsedMessage->getReplyTo()->willReturn(null); |
|
71
|
|
|
$parsedMessage->setReplyTo('_2')->shouldBeCalled(); |
|
72
|
|
|
$parsedMessage->getFrom()->willReturn([]); |
|
73
|
|
|
$parsedMessage->setFrom('_3', '_4')->shouldBeCalled(); |
|
74
|
|
|
$parsedMessage->getTo()->willReturn([]); |
|
75
|
|
|
$parsedMessage->addTo('_5', '_6')->shouldBeCalled(); |
|
76
|
|
|
$parsedMessage->getCc()->willReturn([]); |
|
77
|
|
|
$parsedMessage->addCc('_7', '_8')->shouldBeCalled(); |
|
78
|
|
|
$parsedMessage->getBcc()->willReturn([]); |
|
79
|
|
|
$parsedMessage->addBcc('_9', '_10')->shouldBeCalled(); |
|
80
|
|
|
|
|
81
|
|
|
$this->provider->fetchMailDefinition('App:test', ['param1' => 'yay!'])->willReturn('<email></email>')->shouldBeCalled(); |
|
|
|
|
|
|
82
|
|
|
$this->parser->parseMailDefinition('<email></email>', 'de')->willReturn($parsedMessage)->shouldBeCalled(); |
|
|
|
|
|
|
83
|
|
|
$this->mailer->send($parsedMessage, null)->shouldBeCalled(); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$fixture->send('App:test', ['param1' => 'yay!']); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param null $locale |
|
91
|
|
|
* @param array $defaults |
|
92
|
|
|
* |
|
93
|
|
|
* @return SystemMailer |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function createFixture($locale = null, $defaults = []) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->provider = $this->prophesize(ProviderInterface::class); |
|
|
|
|
|
|
98
|
|
|
$this->parser = $this->prophesize(ParserInterface::class); |
|
|
|
|
|
|
99
|
|
|
$this->mailer = $this->prophesize(MailerInterface::class); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
$defaults = $this->mergeDefaults($defaults); |
|
102
|
|
|
|
|
103
|
|
|
return new SystemMailer($this->provider->reveal(), $this->parser->reveal(), $this->mailer->reveal(), $locale, $defaults); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param array $defaults |
|
108
|
|
|
* |
|
109
|
|
|
* @return array |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function mergeDefaults(array $defaults = []) |
|
112
|
|
|
{ |
|
113
|
|
|
return array_replace_recursive([ |
|
114
|
|
|
'subject' => '', |
|
115
|
|
|
'replyTo' => '', |
|
116
|
|
|
'from' => [ |
|
117
|
|
|
'email' => '', |
|
118
|
|
|
'name' => '', |
|
119
|
|
|
], |
|
120
|
|
|
'to' => [ |
|
121
|
|
|
'email' => '', |
|
122
|
|
|
'name' => '', |
|
123
|
|
|
], |
|
124
|
|
|
'cc' => [ |
|
125
|
|
|
'email' => '', |
|
126
|
|
|
'name' => '', |
|
127
|
|
|
], |
|
128
|
|
|
'bcc' => [ |
|
129
|
|
|
'email' => '', |
|
130
|
|
|
'name' => '', |
|
131
|
|
|
], |
|
132
|
|
|
], $defaults); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.