|
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\Product\Resolver; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use PhpSpec\ObjectBehavior; |
|
18
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
|
19
|
|
|
use Sylius\Component\Product\Model\ProductOptionInterface; |
|
20
|
|
|
use Sylius\Component\Product\Model\ProductOptionValueInterface; |
|
21
|
|
|
use Sylius\Component\Product\Model\ProductVariantInterface; |
|
22
|
|
|
use Sylius\Component\Product\Resolver\AvailableProductOptionValuesResolverInterface; |
|
23
|
|
|
|
|
24
|
|
|
class AvailableProductOptionValuesResolverSpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
private const PRODUCT_CODE = 'PRODUCT_CODE'; |
|
27
|
|
|
|
|
28
|
|
|
private const PRODUCT_OPTION_CODE = 'PRODUCT_OPTION_CODE'; |
|
29
|
|
|
|
|
30
|
|
|
function let( |
|
31
|
|
|
ProductInterface $product, |
|
32
|
|
|
ProductOptionInterface $productOption |
|
33
|
|
|
) { |
|
34
|
|
|
$product->getCode()->willReturn(self::PRODUCT_CODE); |
|
35
|
|
|
$productOption->getCode()->willReturn(self::PRODUCT_OPTION_CODE); |
|
36
|
|
|
$product->hasOption($productOption)->willReturn(true); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_implements_available_product_options_resolver_interface() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldHaveType(AvailableProductOptionValuesResolverInterface::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_throws_if_option_does_not_belong_to_product( |
|
45
|
|
|
ProductInterface $product, |
|
46
|
|
|
ProductOptionInterface $productOption |
|
47
|
|
|
) { |
|
48
|
|
|
$product->hasOption($productOption)->willReturn(false); |
|
49
|
|
|
|
|
50
|
|
|
$this->shouldThrow( |
|
51
|
|
|
new \InvalidArgumentException( |
|
52
|
|
|
sprintf( |
|
53
|
|
|
'Cannot resolve available product option values. Option "%s" does not belong to product "%s".', |
|
54
|
|
|
self::PRODUCT_CODE, |
|
55
|
|
|
self::PRODUCT_OPTION_CODE |
|
56
|
|
|
) |
|
57
|
|
|
) |
|
58
|
|
|
)->during('resolve', [$product, $productOption]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function it_filters_out_values_without_related_enabled_variants( |
|
62
|
|
|
ProductInterface $product, |
|
63
|
|
|
ProductOptionInterface $productOption, |
|
64
|
|
|
ProductOptionValueInterface $productOptionValue1, |
|
65
|
|
|
ProductOptionValueInterface $productOptionValue2, |
|
66
|
|
|
ProductVariantInterface $productVariant |
|
67
|
|
|
) { |
|
68
|
|
|
$productOption->getValues()->willReturn( |
|
69
|
|
|
new ArrayCollection( |
|
70
|
|
|
[ |
|
71
|
|
|
$productOptionValue1->getWrappedObject(), |
|
72
|
|
|
$productOptionValue2->getWrappedObject(), |
|
73
|
|
|
] |
|
74
|
|
|
) |
|
75
|
|
|
); |
|
76
|
|
|
$product->getEnabledVariants()->willReturn(new ArrayCollection([$productVariant->getWrappedObject()])); |
|
77
|
|
|
$productVariant->hasOptionValue($productOptionValue1)->willReturn(true); |
|
78
|
|
|
$productVariant->hasOptionValue($productOptionValue2)->willReturn(false); |
|
79
|
|
|
|
|
80
|
|
|
$this->resolve($product, $productOption)->shouldHaveCount(1); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|