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\CartChangeListener; |
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 CartChangeListenerSpec 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(CartChangeListener::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_recalculates_cart_on_add(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->recalculateOrderOnAdd($event); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_recalculates_cart_and_remove_item_on_delete(OrderProcessorInterface $orderProcessor, ObjectManager $manager, GenericEvent $event, OrderItemInterface $orderItem, OrderInterface $order) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$event->getSubject()->willReturn($orderItem); |
48
|
|
|
$orderItem->getOrder()->willReturn($order); |
49
|
|
|
|
50
|
|
|
$order->removeItem($orderItem)->shouldBeCalled(); |
51
|
|
|
$orderProcessor->process($order)->shouldBeCalled(); |
52
|
|
|
|
53
|
|
|
$this->recalculateOrderOnDelete($event); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.