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

it_converts_fractional_currency_properly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 6
dl 0
loc 27
rs 9.7998
c 0
b 0
f 0
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\QueryBuilder;
14
15
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
16
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\PriceNameResolverInterface;
17
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\HasPriceBetweenQueryBuilder;
18
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
19
use Elastica\Query\Range;
20
use PhpSpec\ObjectBehavior;
21
use Sylius\Component\Channel\Context\ChannelContextInterface;
22
use Sylius\Component\Core\Model\ChannelInterface;
23
use Sylius\Component\Currency\Context\CurrencyContextInterface;
24
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
25
use Sylius\Component\Currency\Model\CurrencyInterface;
26
27
final class HasPriceBetweenQueryBuilderSpec 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
        PriceNameResolverInterface $priceNameResolver,
31
        ConcatedNameResolverInterface $channelPricingNameResolver,
32
        ChannelContextInterface $channelContext,
33
        CurrencyContextInterface $currencyContext,
34
        CurrencyConverterInterface $currencyConverter
35
    ): void {
36
        $this->beConstructedWith(
37
            $priceNameResolver,
38
            $channelPricingNameResolver,
39
            $channelContext,
40
            $currencyContext,
41
            $currencyConverter
42
        );
43
    }
44
45
    function it_is_initializable(): 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...
46
    {
47
        $this->shouldHaveType(HasPriceBetweenQueryBuilder::class);
48
    }
49
50
    function it_implements_query_builder_interface(): void
51
    {
52
        $this->shouldHaveType(QueryBuilderInterface::class);
53
    }
54
55
    function it_builds_query(
56
        PriceNameResolverInterface $priceNameResolver,
57
        ChannelContextInterface $channelContext,
58
        ChannelInterface $channel,
59
        CurrencyContextInterface $currencyContext,
60
        CurrencyInterface $currency,
61
        ConcatedNameResolverInterface $channelPricingNameResolver
62
    ): void {
63
        $channel->getCode()->willReturn('web');
64
        $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

64
        $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...
65
        $priceNameResolver->resolveMinPriceName()->willReturn('min_price');
66
        $priceNameResolver->resolveMaxPriceName()->willReturn('max_price');
67
        $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

67
        $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...
68
        $currency->getCode()->willReturn('USD');
69
        $currencyContext->getCurrencyCode()->willReturn('USD');
70
71
        $channelPricingNameResolver->resolvePropertyName('web')->willReturn('web');
72
73
        $this->buildQuery([
0 ignored issues
show
Bug introduced by
The method buildQuery() does not exist on spec\BitBag\SyliusElasti...BetweenQueryBuilderSpec. 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

73
        $this->/** @scrutinizer ignore-call */ 
74
               buildQuery([
Loading history...
74
            'min_price' => '200',
75
            'max_price' => '1000',
76
        ])->shouldBeAnInstanceOf(Range::class);
77
    }
78
79
    function it_converts_fractional_currency_properly(
80
        PriceNameResolverInterface $priceNameResolver,
81
        ChannelContextInterface $channelContext,
82
        ChannelInterface $channel,
83
        CurrencyContextInterface $currencyContext,
84
        CurrencyInterface $currency,
85
        ConcatedNameResolverInterface $channelPricingNameResolver
86
    ): void {
87
        $channel->getCode()->willReturn('web');
88
        $channelContext->getChannel()->willReturn($channel);
89
        $priceNameResolver->resolveMinPriceName()->willReturn('min_price');
90
        $priceNameResolver->resolveMaxPriceName()->willReturn('max_price');
91
        $channel->getBaseCurrency()->willReturn($currency);
92
        $currency->getCode()->willReturn('USD');
93
        $currencyContext->getCurrencyCode()->willReturn('USD');
94
95
        $channelPricingNameResolver->resolvePropertyName('web')->willReturn('web');
96
97
        $range = $this->buildQuery([
98
            'min_price' => '1,23',
99
            'max_price' => '1000,51',
100
        ]);
101
102
        $range->getParam('web')->shouldReturn(
103
            [
104
                'gte' => 123,
105
                'lte' => 100051,
106
            ]
107
        );
108
    }
109
}
110