Completed
Push — 1.0 ( 3bca9c...afd9f8 )
by Kamil
31:40
created

SwiftMailerAdapterSpec::it_sends_an_email()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 4
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\Component\Mailer\Event\EmailSendEvent;
19
use Sylius\Component\Mailer\Model\EmailInterface;
20
use Sylius\Component\Mailer\Renderer\RenderedEmail;
21
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter;
22
use Sylius\Component\Mailer\SyliusMailerEvents;
23
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
24
25
final class SwiftMailerAdapterSpec extends ObjectBehavior
26
{
27
    function let(\Swift_Mailer $mailer): void
28
    {
29
        $this->beConstructedWith($mailer);
30
    }
31
32
    function it_is_an_adapter(): void
33
    {
34
        $this->shouldHaveType(AbstractAdapter::class);
35
    }
36
37
    function it_sends_an_email(
38
        \Swift_Mailer $mailer,
39
        EmailInterface $email,
40
        EventDispatcherInterface $dispatcher,
41
        RenderedEmail $renderedEmail
42
    ): void {
43
        $this->setEventDispatcher($dispatcher);
44
45
        $renderedEmail->getSubject()->shouldBeCalled()->willReturn('subject');
46
        $renderedEmail->getBody()->shouldBeCalled()->willReturn('body');
47
48
        $dispatcher->dispatch(
49
            SyliusMailerEvents::EMAIL_PRE_SEND,
50
            Argument::type(EmailSendEvent::class)
51
        )->shouldBeCalled();
52
53
        $mailer->send(Argument::type('\Swift_Message'))->shouldBeCalled();
54
55
        $dispatcher->dispatch(
56
            SyliusMailerEvents::EMAIL_POST_SEND,
57
            Argument::type(EmailSendEvent::class)
58
        )->shouldBeCalled();
59
60
        $this->send(
61
            ['[email protected]'],
62
            '[email protected]',
63
            'arnaud',
64
            $renderedEmail,
65
            $email,
66
            []
67
        );
68
    }
69
}
70