Completed
Push — master ( 8e33ff...1a8186 )
by Kamil
47:07 queued 13:42
created

UnpaidOrdersStateUpdaterSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
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 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_an_expired_orders_state_updater_interface() 0 4 1
A it_cancels_unpaid_orders() 0 21 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Core\Updater;
15
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use SM\Factory\Factory;
19
use SM\StateMachine\StateMachineInterface;
20
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
21
use Sylius\Component\Core\Updater\UnpaidOrdersStateUpdaterInterface;
22
use Sylius\Component\Order\Model\OrderInterface;
23
use Sylius\Component\Order\OrderTransitions;
24
25
final class UnpaidOrdersStateUpdaterSpec extends ObjectBehavior
26
{
27
    function let(OrderRepositoryInterface $orderRepository, Factory $stateMachineFactory): void
28
    {
29
        $this->beConstructedWith($orderRepository, $stateMachineFactory, '10 months');
30
    }
31
32
    function it_implements_an_expired_orders_state_updater_interface(): void
33
    {
34
        $this->shouldImplement(UnpaidOrdersStateUpdaterInterface::class);
35
    }
36
37
    function it_cancels_unpaid_orders(
38
        Factory $stateMachineFactory,
39
        OrderInterface $firstOrder,
40
        OrderInterface $secondOrder,
41
        OrderRepositoryInterface $orderRepository,
42
        StateMachineInterface $firstOrderStateMachine,
43
        StateMachineInterface $secondOrderStateMachine
44
    ): void {
45
        $orderRepository->findOrdersUnpaidSince(Argument::type(\DateTimeInterface::class))->willReturn([
46
           $firstOrder,
47
           $secondOrder,
48
        ]);
49
50
        $stateMachineFactory->get($firstOrder, 'sylius_order')->willReturn($firstOrderStateMachine);
51
        $stateMachineFactory->get($secondOrder, 'sylius_order')->willReturn($secondOrderStateMachine);
52
53
        $firstOrderStateMachine->apply(OrderTransitions::TRANSITION_CANCEL)->shouldBeCalled();
54
        $secondOrderStateMachine->apply(OrderTransitions::TRANSITION_CANCEL)->shouldBeCalled();
55
56
        $this->cancel();
57
    }
58
}
59