Completed
Push — master ( 9f1cb3...cf412b )
by Kamil
24:31
created

SwiftMailerAdapterSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_is_an_adapter() 0 4 1
B it_sends_an_email() 0 32 1
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
namespace spec\Sylius\Bundle\MailerBundle\Sender\Adapter;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter;
17
use Sylius\Component\Mailer\Event\EmailSendEvent;
18
use Sylius\Component\Mailer\Model\EmailInterface;
19
use Sylius\Component\Mailer\Renderer\RenderedEmail;
20
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter;
21
use Sylius\Component\Mailer\SyliusMailerEvents;
22
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23
24
final class SwiftMailerAdapterSpec extends ObjectBehavior
25
{
26
    function let(\Swift_Mailer $mailer)
27
    {
28
        $this->beConstructedWith($mailer);
29
    }
30
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType(SwiftMailerAdapter::class);
34
    }
35
36
    function it_is_an_adapter()
37
    {
38
        $this->shouldHaveType(AbstractAdapter::class);
39
    }
40
41
    function it_sends_an_email(
42
        \Swift_Mailer $mailer,
43
        EmailInterface $email,
44
        EventDispatcherInterface $dispatcher,
45
        RenderedEmail $renderedEmail
46
    ) {
47
        $this->setEventDispatcher($dispatcher);
48
49
        $renderedEmail->getSubject()->shouldBeCalled()->willReturn('subject');
50
        $renderedEmail->getBody()->shouldBeCalled()->willReturn('body');
51
52
        $dispatcher->dispatch(
53
            SyliusMailerEvents::EMAIL_PRE_SEND,
54
            Argument::type(EmailSendEvent::class)
55
        )->shouldBeCalled();
56
57
        $mailer->send(Argument::type('\Swift_Message'))->shouldBeCalled();
58
59
        $dispatcher->dispatch(
60
            SyliusMailerEvents::EMAIL_POST_SEND,
61
            Argument::type(EmailSendEvent::class)
62
        )->shouldBeCalled();
63
64
        $this->send(
65
            ['[email protected]'],
66
            '[email protected]',
67
            'arnaud',
68
            $renderedEmail,
69
            $email,
70
            []
71
        );
72
    }
73
}
74