1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\MailerBundle\Sender\Adapter; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter; |
19
|
|
|
use Sylius\Component\Mailer\Event\EmailSendEvent; |
20
|
|
|
use Sylius\Component\Mailer\Model\EmailInterface; |
21
|
|
|
use Sylius\Component\Mailer\Renderer\RenderedEmail; |
22
|
|
|
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter; |
23
|
|
|
use Sylius\Component\Mailer\SyliusMailerEvents; |
24
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
25
|
|
|
|
26
|
|
|
final class SwiftMailerAdapterSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(\Swift_Mailer $mailer): void |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($mailer); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_an_adapter(): void |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType(AbstractAdapter::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_sends_an_email( |
39
|
|
|
\Swift_Mailer $mailer, |
40
|
|
|
EmailInterface $email, |
41
|
|
|
EventDispatcherInterface $dispatcher, |
42
|
|
|
RenderedEmail $renderedEmail |
43
|
|
|
): void { |
44
|
|
|
$this->setEventDispatcher($dispatcher); |
45
|
|
|
|
46
|
|
|
$renderedEmail->getSubject()->shouldBeCalled()->willReturn('subject'); |
47
|
|
|
$renderedEmail->getBody()->shouldBeCalled()->willReturn('body'); |
48
|
|
|
|
49
|
|
|
$dispatcher->dispatch( |
50
|
|
|
SyliusMailerEvents::EMAIL_PRE_SEND, |
51
|
|
|
Argument::type(EmailSendEvent::class) |
52
|
|
|
)->shouldBeCalled(); |
53
|
|
|
|
54
|
|
|
$mailer->send(Argument::type('\Swift_Message'))->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$dispatcher->dispatch( |
57
|
|
|
SyliusMailerEvents::EMAIL_POST_SEND, |
58
|
|
|
Argument::type(EmailSendEvent::class) |
59
|
|
|
)->shouldBeCalled(); |
60
|
|
|
|
61
|
|
|
$this->send( |
62
|
|
|
['[email protected]'], |
63
|
|
|
'[email protected]', |
64
|
|
|
'arnaud', |
65
|
|
|
$renderedEmail, |
66
|
|
|
$email, |
67
|
|
|
[] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|