1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Gewebe\SyliusProductDepositPlugin\Provider; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ChannelDepositInterface; |
9
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface; |
10
|
|
|
use Gewebe\SyliusProductDepositPlugin\Provider\ProductVariantsDepositsProvider; |
11
|
|
|
use Gewebe\SyliusProductDepositPlugin\Provider\ProductVariantsDepositsProviderInterface; |
12
|
|
|
use PhpSpec\ObjectBehavior; |
13
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
14
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
15
|
|
|
use Sylius\Component\Product\Model\ProductOptionValueInterface; |
16
|
|
|
|
17
|
|
|
final class ProductVariantsDepositsProviderSpec extends ObjectBehavior |
18
|
|
|
{ |
19
|
|
|
function it_is_initializable(): void |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$this->shouldHaveType(ProductVariantsDepositsProvider::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function it_implements_product_variants_deposits_provider(): void |
25
|
|
|
{ |
26
|
|
|
$this->shouldImplement(ProductVariantsDepositsProviderInterface::class); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_provide_product_variants_deposit( |
30
|
|
|
ProductInterface $product, |
31
|
|
|
ProductVariantInterface $productVariant, |
32
|
|
|
ProductOptionValueInterface $productOptionValue, |
33
|
|
|
ChannelInterface $channel, |
34
|
|
|
ChannelDepositInterface $channelDeposit |
35
|
|
|
): void { |
36
|
|
|
$channelDeposit->getPrice()->willReturn(50); |
37
|
|
|
$productVariant->getChannelDepositForChannel($channel)->willReturn($channelDeposit); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$productOptionValue->getCode()->willReturn('1 liter'); |
40
|
|
|
$productOptionValue->getOptionCode()->willReturn('1_liter'); |
41
|
|
|
$productOptionValues = new ArrayCollection([$productOptionValue->getWrappedObject()]); |
|
|
|
|
42
|
|
|
$productVariant->getOptionValues()->willReturn($productOptionValues); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$variants = new ArrayCollection([$productVariant->getWrappedObject()]); |
|
|
|
|
45
|
|
|
$product->getVariants()->willReturn($variants); |
46
|
|
|
|
47
|
|
|
$variantsDeposit = $this->provideVariantsDeposits($product, $channel); |
|
|
|
|
48
|
|
|
$variantsDeposit->shouldHaveCount(1); |
49
|
|
|
$variantsDeposit->shouldReturn([ |
50
|
|
|
0 => [ |
51
|
|
|
'1_liter' => '1 liter', |
52
|
|
|
'value' => 50 |
53
|
|
|
] |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.