|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace spec\BitBag\SyliusElasticsearchPlugin\Transformer\Product; |
|
6
|
|
|
|
|
7
|
|
|
use BitBag\SyliusElasticsearchPlugin\Transformer\Product\TransformerInterface; |
|
8
|
|
|
use PhpSpec\ObjectBehavior; |
|
9
|
|
|
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface; |
|
10
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
11
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
12
|
|
|
use Sylius\Component\Core\Model\ChannelPricingInterface; |
|
13
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
14
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
15
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
|
16
|
|
|
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; |
|
17
|
|
|
|
|
18
|
|
|
final class ChannelPricingTransformerSpec extends ObjectBehavior |
|
19
|
|
|
{ |
|
20
|
|
|
function let( |
|
|
|
|
|
|
21
|
|
|
ChannelContextInterface $channelContext, |
|
22
|
|
|
ProductVariantResolverInterface $productVariantResolver, |
|
23
|
|
|
MoneyFormatterInterface $moneyFormatter |
|
24
|
|
|
): void { |
|
25
|
|
|
$this->beConstructedWith($channelContext, $productVariantResolver, $moneyFormatter); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
function it_is_a_transformer(): void |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
$this->shouldImplement(TransformerInterface::class); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_transforms_product_channel_prices_into_formatted_price( |
|
34
|
|
|
ChannelContextInterface $channelContext, |
|
35
|
|
|
ProductVariantResolverInterface $productVariantResolver, |
|
36
|
|
|
MoneyFormatterInterface $moneyFormatter, |
|
37
|
|
|
CurrencyInterface $currency, |
|
38
|
|
|
ChannelInterface $channel, |
|
39
|
|
|
ProductVariantInterface $productVariant, |
|
40
|
|
|
ProductInterface $product, |
|
41
|
|
|
ChannelPricingInterface $channelPricing |
|
42
|
|
|
): void { |
|
43
|
|
|
$currency->getCode()->willReturn('USD'); |
|
44
|
|
|
$channel->getBaseCurrency()->willReturn($currency); |
|
|
|
|
|
|
45
|
|
|
$channelContext->getChannel()->willReturn($channel); |
|
|
|
|
|
|
46
|
|
|
$productVariantResolver->getVariant($product)->willReturn($productVariant); |
|
|
|
|
|
|
47
|
|
|
$channelPricing->getPrice()->willReturn(10); |
|
48
|
|
|
$productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$moneyFormatter->format(10, 'USD'); |
|
51
|
|
|
|
|
52
|
|
|
$this->transform($product); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
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.