Completed
Push — currency-cookie ( 8ef560...28b724 )
by Kamil
24:47
created

AddToCartListenerSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_recalculates_cart() 0 10 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\ApiBundle\EventListener;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Bundle\ApiBundle\EventListener\AddToCartListener;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Core\Model\OrderItemInterface;
19
use Sylius\Component\Order\Processor\OrderProcessorInterface;
20
use Symfony\Component\EventDispatcher\GenericEvent;
21
22
final class AddToCartListenerSpec extends ObjectBehavior
23
{
24
    function let(OrderProcessorInterface $orderProcessor, ObjectManager $manager)
25
    {
26
        $this->beConstructedWith($orderProcessor, $manager);
27
    }
28
29
    function it_is_initializable()
30
    {
31
        $this->shouldHaveType(AddToCartListener::class);
32
    }
33
34
    function it_recalculates_cart(OrderProcessorInterface $orderProcessor, ObjectManager $manager, GenericEvent $event, OrderItemInterface $orderItem, OrderInterface $order)
35
    {
36
        $event->getSubject()->willReturn($orderItem);
37
        $orderItem->getOrder()->willReturn($order);
38
39
        $orderProcessor->process($order)->shouldBeCalled();
40
        $manager->persist($order)->shouldBeCalled();
41
42
        $this->recalculateOrder($event);
43
    }
44
}
45