Completed
Push — scalar-types/ui ( 162de3 )
by Kamil
22:15
created

AvailabilityCheckerSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
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\Inventory\Checker;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface;
18
use Sylius\Component\Inventory\Model\StockableInterface;
19
20
/**
21
 * @author Paweł Jędrzejewski <[email protected]>
22
 */
23
final class AvailabilityCheckerSpec extends ObjectBehavior
24
{
25
    function it_is_an_inventory_availability_checker(): void
26
    {
27
        $this->shouldImplement(AvailabilityCheckerInterface::class);
28
    }
29
30
    function it_recognizes_stockable_as_available_if_on_hand_quantity_is_greater_than_0(StockableInterface $stockable): void
31
    {
32
        $stockable->isTracked()->willReturn(true);
33
        $stockable->getOnHand()->willReturn(5);
34
        $stockable->getOnHold()->willReturn(0);
35
36
        $this->isStockAvailable($stockable)->shouldReturn(true);
37
    }
38
39
    function it_recognizes_stockable_as_not_available_if_on_hand_quantity_is_equal_to_0(StockableInterface $stockable): void
40
    {
41
        $stockable->isTracked()->willReturn(true);
42
        $stockable->getOnHand()->willReturn(0);
43
        $stockable->getOnHold()->willReturn(0);
44
45
        $this->isStockAvailable($stockable)->shouldReturn(false);
46
    }
47
48
    function it_recognizes_stockable_as_available_if_on_hold_quantity_is_less_than_on_hand(
49
        StockableInterface $stockable
50
    ): void {
51
        $stockable->isTracked()->willReturn(true);
52
        $stockable->getOnHand()->willReturn(5);
53
        $stockable->getOnHold()->willReturn(4);
54
55
        $this->isStockAvailable($stockable)->shouldReturn(true);
56
    }
57
58
    function it_recognizes_stockable_as_not_available_if_on_hold_quantity_is_same_as_on_hand(
59
        StockableInterface $stockable
60
    ): void {
61
        $stockable->isTracked()->willReturn(true);
62
        $stockable->getOnHand()->willReturn(5);
63
        $stockable->getOnHold()->willReturn(5);
64
65
        $this->isStockAvailable($stockable)->shouldReturn(false);
66
    }
67
68
    function it_recognizes_stockable_as_sufficient_if_on_hand_minus_on_hold_quantity_is_greater_than_the_required_quantity(
69
        StockableInterface $stockable
70
    ): void {
71
        $stockable->isTracked()->willReturn(true);
72
        $stockable->getOnHand()->willReturn(10);
73
        $stockable->getOnHold()->willReturn(3);
74
75
        $this->isStockSufficient($stockable, 5)->shouldReturn(true);
76
    }
77
78
    function it_recognizes_stockable_as_sufficient_if_on_hand_minus_on_hold_quantity_is_equal_to_the_required_quantity(
79
        StockableInterface $stockable
80
    ): void {
81
        $stockable->isTracked()->willReturn(true);
82
        $stockable->getOnHand()->willReturn(10);
83
        $stockable->getOnHold()->willReturn(5);
84
85
        $this->isStockSufficient($stockable, 5)->shouldReturn(true);
86
    }
87
88
    function it_recognizes_stockable_as_available_or_sufficent_if_it_is_not_tracked(StockableInterface $stockable): void
89
    {
90
        $stockable->isTracked()->willReturn(false);
91
92
        $this->isStockAvailable($stockable)->shouldReturn(true);
93
        $this->isStockSufficient($stockable, 42)->shouldReturn(true);
94
    }
95
}
96