|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace spec\BitBag\SyliusElasticsearchPlugin\Transformer\Product; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusElasticsearchPlugin\Transformer\Product\TransformerInterface; |
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface; |
|
18
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
19
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\ChannelPricingInterface; |
|
21
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
22
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
23
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
|
24
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
|
25
|
|
|
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; |
|
26
|
|
|
|
|
27
|
|
|
final class ChannelPricingTransformerSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let( |
|
|
|
|
|
|
30
|
|
|
ChannelContextInterface $channelContext, |
|
31
|
|
|
LocaleContextInterface $localeContext, |
|
32
|
|
|
ProductVariantResolverInterface $productVariantResolver, |
|
33
|
|
|
MoneyFormatterInterface $moneyFormatter |
|
34
|
|
|
): void { |
|
35
|
|
|
$this->beConstructedWith($channelContext, $localeContext, $productVariantResolver, $moneyFormatter); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_is_a_transformer(): void |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$this->shouldImplement(TransformerInterface::class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_transforms_product_channel_prices_into_formatted_price( |
|
44
|
|
|
ChannelContextInterface $channelContext, |
|
45
|
|
|
LocaleContextInterface $localeContext, |
|
46
|
|
|
ProductVariantResolverInterface $productVariantResolver, |
|
47
|
|
|
MoneyFormatterInterface $moneyFormatter, |
|
48
|
|
|
CurrencyInterface $currency, |
|
49
|
|
|
ChannelInterface $channel, |
|
50
|
|
|
ProductVariantInterface $productVariant, |
|
51
|
|
|
ProductInterface $product, |
|
52
|
|
|
ChannelPricingInterface $channelPricing |
|
53
|
|
|
): void { |
|
54
|
|
|
$currency->getCode()->willReturn('USD'); |
|
55
|
|
|
$channel->getBaseCurrency()->willReturn($currency); |
|
|
|
|
|
|
56
|
|
|
$channelContext->getChannel()->willReturn($channel); |
|
|
|
|
|
|
57
|
|
|
$localeContext->getLocaleCode()->willReturn('en_US'); |
|
58
|
|
|
$productVariantResolver->getVariant($product)->willReturn($productVariant); |
|
|
|
|
|
|
59
|
|
|
$channelPricing->getPrice()->willReturn(10); |
|
60
|
|
|
$productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$moneyFormatter->format(10, 'USD', 'en_US'); |
|
63
|
|
|
|
|
64
|
|
|
$this->transform($product); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
function it_returns_null_when_product_doeas_not_have_any_variant( |
|
68
|
|
|
ChannelContextInterface $channelContext, |
|
69
|
|
|
ProductVariantResolverInterface $productVariantResolver, |
|
70
|
|
|
MoneyFormatterInterface $moneyFormatter, |
|
|
|
|
|
|
71
|
|
|
CurrencyInterface $currency, |
|
72
|
|
|
ChannelInterface $channel, |
|
73
|
|
|
ProductVariantInterface $productVariant, |
|
|
|
|
|
|
74
|
|
|
ProductInterface $product, |
|
75
|
|
|
ChannelPricingInterface $channelPricing |
|
|
|
|
|
|
76
|
|
|
): void { |
|
77
|
|
|
$currency->getCode()->willReturn('USD'); |
|
78
|
|
|
$channel->getBaseCurrency()->willReturn($currency); |
|
79
|
|
|
$channelContext->getChannel()->willReturn($channel); |
|
80
|
|
|
$productVariantResolver->getVariant($product)->willReturn(null); |
|
81
|
|
|
|
|
82
|
|
|
$this->transform($product)->shouldBeNull(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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.