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\ProductVariantInterface; |
9
|
|
|
use Gewebe\SyliusProductDepositPlugin\Provider\ProductVariantsDepositsProvider; |
10
|
|
|
use Gewebe\SyliusProductDepositPlugin\Provider\ProductVariantsDepositsProviderInterface; |
11
|
|
|
use PhpSpec\ObjectBehavior; |
12
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
13
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
14
|
|
|
use Sylius\Component\Product\Model\ProductOptionValueInterface; |
15
|
|
|
|
16
|
|
|
final class ProductVariantsDepositsProviderSpec extends ObjectBehavior |
17
|
|
|
{ |
18
|
|
|
function it_is_initializable(): void |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$this->shouldHaveType(ProductVariantsDepositsProvider::class); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_implements_product_variants_deposits_provider(): void |
24
|
|
|
{ |
25
|
|
|
$this->shouldImplement(ProductVariantsDepositsProviderInterface::class); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_provide_product_variants_deposit( |
29
|
|
|
ProductInterface $product, |
30
|
|
|
ProductVariantInterface $productVariant, |
31
|
|
|
ProductOptionValueInterface $productOptionValue, |
32
|
|
|
ChannelInterface $channel |
33
|
|
|
): void { |
34
|
|
|
$productVariant->getDepositPriceByChannel($channel)->willReturn(50); |
35
|
|
|
|
36
|
|
|
$productOptionValue->getCode()->willReturn('1 liter'); |
37
|
|
|
$productOptionValue->getOptionCode()->willReturn('1_liter'); |
38
|
|
|
$productOptionValues = new ArrayCollection([$productOptionValue->getWrappedObject()]); |
|
|
|
|
39
|
|
|
$productVariant->getOptionValues()->willReturn($productOptionValues); |
|
|
|
|
40
|
|
|
|
41
|
|
|
$variants = new ArrayCollection([$productVariant->getWrappedObject()]); |
|
|
|
|
42
|
|
|
$product->getVariants()->willReturn($variants); |
43
|
|
|
|
44
|
|
|
$variantsDeposit = $this->provideVariantsDeposits($product, $channel); |
|
|
|
|
45
|
|
|
$variantsDeposit->shouldHaveCount(1); |
46
|
|
|
$variantsDeposit->shouldReturn([ |
47
|
|
|
0 => [ |
48
|
|
|
'1_liter' => '1 liter', |
49
|
|
|
'value' => 50 |
50
|
|
|
] |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
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.