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\Bundle\InventoryBundle\Validator\Constraints; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Bundle\InventoryBundle\Validator\Constraints\InStock; |
18
|
|
|
use Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface; |
19
|
|
|
use Sylius\Component\Inventory\Model\InventoryUnitInterface; |
20
|
|
|
use Sylius\Component\Inventory\Model\StockableInterface; |
21
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessor; |
22
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
23
|
|
|
|
24
|
|
|
final class InStockValidatorSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function let(AvailabilityCheckerInterface $availabilityChecker): void |
27
|
|
|
{ |
28
|
|
|
$this->beConstructedWith($availabilityChecker); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_is_a_constraint_validator(): void |
32
|
|
|
{ |
33
|
|
|
$this->shouldHaveType(ConstraintValidator::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_does_not_add_violation_if_there_is_no_stockable( |
37
|
|
|
InventoryUnitInterface $inventoryUnit, |
38
|
|
|
PropertyAccessor $propertyAccessor |
39
|
|
|
): void { |
40
|
|
|
$propertyAccessor->getValue($inventoryUnit, 'stockable')->willReturn(null); |
41
|
|
|
|
42
|
|
|
$constraint = new InStock(); |
43
|
|
|
|
44
|
|
|
$this->validate($inventoryUnit, $constraint); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function it_does_not_add_violation_if_there_is_no_quantity( |
48
|
|
|
InventoryUnitInterface $inventoryUnit, |
49
|
|
|
PropertyAccessor $propertyAccessor, |
50
|
|
|
StockableInterface $stockable |
51
|
|
|
): void { |
52
|
|
|
$propertyAccessor->getValue($inventoryUnit, 'stockable')->willReturn($stockable); |
53
|
|
|
$propertyAccessor->getValue($inventoryUnit, 'quantity')->willReturn(null); |
54
|
|
|
|
55
|
|
|
$constraint = new InStock(); |
56
|
|
|
|
57
|
|
|
$this->validate($inventoryUnit, $constraint); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_does_not_add_violation_if_stock_is_sufficient( |
61
|
|
|
AvailabilityCheckerInterface $availabilityChecker, |
62
|
|
|
InventoryUnitInterface $inventoryUnit, |
63
|
|
|
PropertyAccessor $propertyAccessor, |
64
|
|
|
StockableInterface $stockable |
65
|
|
|
): void { |
66
|
|
|
$propertyAccessor->getValue($inventoryUnit, 'stockable')->willReturn($stockable); |
67
|
|
|
$propertyAccessor->getValue($inventoryUnit, 'quantity')->willReturn(1); |
68
|
|
|
|
69
|
|
|
$availabilityChecker->isStockSufficient($stockable, 1)->willReturn(true); |
70
|
|
|
|
71
|
|
|
$constraint = new InStock(); |
72
|
|
|
|
73
|
|
|
$this->validate($inventoryUnit, $constraint); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|