Passed
Pull Request — master (#156)
by
unknown
07:04
created

ChannelPricingTransformerSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_returns_null_when_product_doeas_not_have_any_variant() 0 16 1
A let() 0 7 1
A it_transforms_product_channel_prices_into_formatted_price() 0 22 1
A it_is_a_transformer() 0 3 1
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(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Currency\Model\CurrencyInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $channel->getBaseCurrency()->/** @scrutinizer ignore-call */ willReturn($currency);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
        $channelContext->getChannel()->willReturn($channel);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Channel\Model\ChannelInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $channelContext->getChannel()->/** @scrutinizer ignore-call */ willReturn($channel);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
        $localeContext->getLocaleCode()->willReturn('en_US');
58
        $productVariantResolver->getVariant($product)->willReturn($productVariant);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Product...ProductVariantInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        $productVariantResolver->getVariant($product)->/** @scrutinizer ignore-call */ willReturn($productVariant);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
        $channelPricing->getPrice()->willReturn(10);
60
        $productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Core\Mo...ChannelPricingInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        $productVariant->getChannelPricingForChannel($channel)->/** @scrutinizer ignore-call */ willReturn($channelPricing);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
62
        $moneyFormatter->format(10, 'USD', 'en_US');
63
64
        $this->transform($product);
0 ignored issues
show
Bug introduced by
The method transform() does not exist on spec\BitBag\SyliusElasti...lPricingTransformerSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        $this->/** @scrutinizer ignore-call */ 
65
               transform($product);
Loading history...
65
    }
66
67
    function it_returns_null_when_product_doeas_not_have_any_variant(
68
        ChannelContextInterface $channelContext,
69
        ProductVariantResolverInterface $productVariantResolver,
70
        MoneyFormatterInterface $moneyFormatter,
0 ignored issues
show
Unused Code introduced by
The parameter $moneyFormatter is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

70
        /** @scrutinizer ignore-unused */ MoneyFormatterInterface $moneyFormatter,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
        CurrencyInterface $currency,
72
        ChannelInterface $channel,
73
        ProductVariantInterface $productVariant,
0 ignored issues
show
Unused Code introduced by
The parameter $productVariant is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

73
        /** @scrutinizer ignore-unused */ ProductVariantInterface $productVariant,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
        ProductInterface $product,
75
        ChannelPricingInterface $channelPricing
0 ignored issues
show
Unused Code introduced by
The parameter $channelPricing is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
        /** @scrutinizer ignore-unused */ ChannelPricingInterface $channelPricing

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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