1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hautzi\SystemMailBundle\Tests\SystemMailer\Mailer; |
4
|
|
|
|
5
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\Mailer\SwiftMailer; |
6
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\ParsedMessage; |
7
|
|
|
use Prophecy\Argument; |
8
|
|
|
|
9
|
|
|
class SwiftMailerTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var SwiftMailer |
13
|
|
|
*/ |
14
|
|
|
protected $fixture; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var \Twig_Environment |
18
|
|
|
*/ |
19
|
|
|
protected $mailer; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->mailer = $this->prophesize(\Swift_Mailer::class); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$this->fixture = new SwiftMailer($this->mailer->reveal()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSendingMailWorks() |
29
|
|
|
{ |
30
|
|
|
$message = new ParsedMessage(); |
31
|
|
|
$message->setFrom('[email protected]', 'from'); |
32
|
|
|
$message->setReplyTo('[email protected]'); |
33
|
|
|
$message->addTo('[email protected]', 'to1'); |
34
|
|
|
$message->addTo('[email protected]', 'to2'); |
35
|
|
|
$message->addCc('[email protected]', 'cc1'); |
36
|
|
|
$message->addCc('[email protected]', 'cc2'); |
37
|
|
|
$message->addBcc('[email protected]', 'bcc1'); |
38
|
|
|
$message->addBcc('[email protected]', 'bcc2'); |
39
|
|
|
$message->setSubject('_subject'); |
40
|
|
|
$message->setMessageText('_text_message'); |
41
|
|
|
$message->setMessageHtml('_html_message'); |
42
|
|
|
|
43
|
|
|
$this->mailer->send(Argument::type(\Swift_Message::class))->shouldBeCalled(); |
44
|
|
|
|
45
|
|
|
$closureExceuted = false; |
46
|
|
|
$this->fixture->send($message, function (\Swift_Message $message) use (&$closureExceuted) { |
47
|
|
|
// from |
48
|
|
|
$this->assertEquals(['[email protected]' => 'from'], $message->getFrom()); |
49
|
|
|
// reply-to |
50
|
|
|
$this->assertEquals(['[email protected]' => null], $message->getReplyTo()); |
51
|
|
|
// to |
52
|
|
|
$this->assertEquals(['[email protected]' => 'to1', '[email protected]' => 'to2'], $message->getTo()); |
53
|
|
|
// cc |
54
|
|
|
$this->assertEquals(['[email protected]' => 'cc1', '[email protected]' => 'cc2'], $message->getCc()); |
55
|
|
|
// bcc |
56
|
|
|
$this->assertEquals(['[email protected]' => 'bcc1', '[email protected]' => 'bcc2'], $message->getBcc()); |
57
|
|
|
|
58
|
|
|
$this->assertEquals('_subject', $message->getSubject()); |
59
|
|
|
$this->assertEquals('_text_message', $message->getBody()); |
60
|
|
|
|
61
|
|
|
$closureExceuted = true; |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
$this->assertTrue($closureExceuted, 'closure was not executed.'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..