Completed
Push — 1.1-coding-standard-fixes ( 71011e )
by Kamil
28:55
created

ProductVariantsPricesProviderSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 84
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_a_variants_prices_provider_interface() 0 4 1
A it_provides_array_containing_product_variant_options_map_with_corresponding_price() 0 71 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\Provider;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
19
use Sylius\Component\Core\Model\ChannelInterface;
20
use Sylius\Component\Core\Model\ProductInterface;
21
use Sylius\Component\Core\Model\ProductVariantInterface;
22
use Sylius\Component\Core\Provider\ProductVariantsPricesProviderInterface;
23
use Sylius\Component\Product\Model\ProductOptionValueInterface;
24
25
final class ProductVariantsPricesProviderSpec extends ObjectBehavior
26
{
27
    function let(ProductVariantPriceCalculatorInterface $productVariantPriceCalculator): void
28
    {
29
        $this->beConstructedWith($productVariantPriceCalculator);
30
    }
31
32
    function it_implements_a_variants_prices_provider_interface(): void
33
    {
34
        $this->shouldImplement(ProductVariantsPricesProviderInterface::class);
35
    }
36
37
    function it_provides_array_containing_product_variant_options_map_with_corresponding_price(
38
        ChannelInterface $channel,
39
        ProductInterface $tShirt,
40
        ProductOptionValueInterface $black,
41
        ProductOptionValueInterface $large,
42
        ProductOptionValueInterface $small,
43
        ProductOptionValueInterface $white,
44
        ProductVariantInterface $blackLargeTShirt,
45
        ProductVariantInterface $blackSmallTShirt,
46
        ProductVariantInterface $whiteLargeTShirt,
47
        ProductVariantInterface $whiteSmallTShirt,
48
        ProductVariantPriceCalculatorInterface $productVariantPriceCalculator
49
    ): void {
50
        $tShirt->getVariants()->willReturn(new ArrayCollection([
51
            $blackSmallTShirt->getWrappedObject(),
52
            $whiteSmallTShirt->getWrappedObject(),
53
            $blackLargeTShirt->getWrappedObject(),
54
            $whiteLargeTShirt->getWrappedObject(),
55
        ]));
56
57
        $blackSmallTShirt->getOptionValues()->willReturn(
58
            new ArrayCollection([$black->getWrappedObject(), $small->getWrappedObject()])
59
        );
60
        $whiteSmallTShirt->getOptionValues()->willReturn(
61
            new ArrayCollection([$white->getWrappedObject(), $small->getWrappedObject()])
62
        );
63
        $blackLargeTShirt->getOptionValues()->willReturn(
64
            new ArrayCollection([$black->getWrappedObject(), $large->getWrappedObject()])
65
        );
66
        $whiteLargeTShirt->getOptionValues()->willReturn(
67
            new ArrayCollection([$white->getWrappedObject(), $large->getWrappedObject()])
68
        );
69
70
        $productVariantPriceCalculator->calculate($blackSmallTShirt, ['channel' => $channel])->willReturn(1000);
71
        $productVariantPriceCalculator->calculate($whiteSmallTShirt, ['channel' => $channel])->willReturn(1500);
72
        $productVariantPriceCalculator->calculate($blackLargeTShirt, ['channel' => $channel])->willReturn(2000);
73
        $productVariantPriceCalculator->calculate($whiteLargeTShirt, ['channel' => $channel])->willReturn(2500);
74
75
        $black->getOptionCode()->willReturn('t_shirt_color');
76
        $white->getOptionCode()->willReturn('t_shirt_color');
77
        $small->getOptionCode()->willReturn('t_shirt_size');
78
        $large->getOptionCode()->willReturn('t_shirt_size');
79
80
        $black->getCode()->willReturn('black');
81
        $white->getCode()->willReturn('white');
82
        $small->getCode()->willReturn('small');
83
        $large->getCode()->willReturn('large');
84
85
        $this->provideVariantsPrices($tShirt, $channel)->shouldReturn([
86
            [
87
                't_shirt_color' => 'black',
88
                't_shirt_size' => 'small',
89
                'value' => 1000,
90
            ],
91
            [
92
                't_shirt_color' => 'white',
93
                't_shirt_size' => 'small',
94
                'value' => 1500,
95
            ],
96
            [
97
                't_shirt_color' => 'black',
98
                't_shirt_size' => 'large',
99
                'value' => 2000,
100
            ],
101
            [
102
                't_shirt_color' => 'white',
103
                't_shirt_size' => 'large',
104
                'value' => 2500,
105
            ],
106
        ]);
107
    }
108
}
109