|
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\OrderBundle\Remover; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
15
|
|
|
use PhpSpec\ObjectBehavior; |
|
16
|
|
|
use Prophecy\Argument; |
|
17
|
|
|
use Sylius\Bundle\OrderBundle\Remover\ExpiredCartsRemover; |
|
18
|
|
|
use Sylius\Bundle\OrderBundle\SyliusExpiredCartsEvents; |
|
19
|
|
|
use Sylius\Component\Order\Model\OrderInterface; |
|
20
|
|
|
use Sylius\Component\Order\Remover\ExpiredCartsRemoverInterface; |
|
21
|
|
|
use Sylius\Component\Order\Repository\OrderRepositoryInterface; |
|
22
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
final class ExpiredCartsRemoverSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let(OrderRepositoryInterface $orderRepository, ObjectManager $orderManager, EventDispatcher $eventDispatcher) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedWith($orderRepository, $orderManager, $eventDispatcher, '2 months'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_is_initializable() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldHaveType(ExpiredCartsRemover::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_implements_an_expired_carts_remover_interface() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldImplement(ExpiredCartsRemoverInterface::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_removes_a_cart_which_has_been_updated_before_configured_date( |
|
45
|
|
|
OrderRepositoryInterface $orderRepository, |
|
46
|
|
|
ObjectManager $orderManager, |
|
47
|
|
|
EventDispatcher $eventDispatcher, |
|
48
|
|
|
OrderInterface $firstCart, |
|
49
|
|
|
OrderInterface $secondCart |
|
50
|
|
|
) { |
|
51
|
|
|
$orderRepository->findCartsNotModifiedSince(Argument::type('\DateTime'))->willReturn([ |
|
52
|
|
|
$firstCart, |
|
53
|
|
|
$secondCart |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$eventDispatcher |
|
57
|
|
|
->dispatch(SyliusExpiredCartsEvents::PRE_REMOVE, Argument::any()) |
|
58
|
|
|
->shouldBeCalled() |
|
59
|
|
|
; |
|
60
|
|
|
|
|
61
|
|
|
$orderManager->remove($firstCart); |
|
62
|
|
|
$orderManager->remove($secondCart); |
|
63
|
|
|
$orderManager->flush(); |
|
64
|
|
|
|
|
65
|
|
|
$eventDispatcher |
|
66
|
|
|
->dispatch(SyliusExpiredCartsEvents::POST_REMOVE, Argument::any()) |
|
67
|
|
|
->shouldBeCalled() |
|
68
|
|
|
; |
|
69
|
|
|
|
|
70
|
|
|
$this->remove(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|