Passed
Pull Request — master (#69)
by Manuele
03:19
created

PriceFacetSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 60
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 13 1
A it_is_initializable() 0 3 1
A it_implements_facet_interface() 0 3 1
A it_returns_histogram_aggregation_for_price_field() 0 7 1
A it_returns_money_formatted_bucket_label() 0 10 1
A it_returns_bool_query_made_of_ranges_based_on_selected_histograms() 0 9 1
1
<?php
2
3
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
4
5
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
6
use BitBag\SyliusElasticsearchPlugin\Facet\PriceFacet;
7
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
8
use Elastica\Aggregation\Histogram;
9
use Elastica\Query\BoolQuery;
10
use Elastica\Query\Range;
11
use PhpSpec\ObjectBehavior;
12
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
13
use Sylius\Component\Core\Context\ShopperContextInterface;
14
use Sylius\Component\Core\Model\Channel;
15
16
class PriceFacetSpec extends ObjectBehavior
17
{
18
    private $interval = 1000000;
19
20
    function let(
21
        ConcatedNameResolverInterface $channelPricingNameResolver,
22
        MoneyFormatterInterface $moneyFormatter,
23
        ShopperContextInterface $shopperContext
24
    ) {
25
        $channel = new Channel();
26
        $channel->setCode('web_us');
27
        $shopperContext->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

27
        $shopperContext->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...
28
        $this->beConstructedWith(
29
            $channelPricingNameResolver,
30
            $moneyFormatter,
31
            $shopperContext,
32
            $this->interval
33
        );
34
    }
35
36
    function it_is_initializable()
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...
37
    {
38
        $this->shouldHaveType(PriceFacet::class);
39
    }
40
41
    function it_implements_facet_interface()
42
    {
43
        $this->shouldHaveType(FacetInterface::class);
44
    }
45
46
    function it_returns_histogram_aggregation_for_price_field(ConcatedNameResolverInterface $channelPricingNameResolver)
47
    {
48
        $channelPricingNameResolver->resolvePropertyName('web_us')->shouldBeCalled()->willReturn('price_web_us');
49
        $expectedHistogram = new Histogram('price', 'price_web_us', $this->interval);
50
        $expectedHistogram->setMinimumDocumentCount(1);
51
52
        $this->getAggregation()->shouldBeLike($expectedHistogram);
0 ignored issues
show
Bug introduced by
The method getAggregation() does not exist on spec\BitBag\SyliusElasti...in\Facet\PriceFacetSpec. 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

52
        $this->/** @scrutinizer ignore-call */ 
53
               getAggregation()->shouldBeLike($expectedHistogram);
Loading history...
53
    }
54
55
    function it_returns_bool_query_made_of_ranges_based_on_selected_histograms(ConcatedNameResolverInterface $channelPricingNameResolver)
56
    {
57
        $channelPricingNameResolver->resolvePropertyName('web_us')->shouldBeCalled()->willReturn('price_web_us');
58
59
        $selectedHistograms = [1000000, 4000000];
60
        $expectedQuery = new BoolQuery();
61
        $expectedQuery->addShould(new Range('price_web_us', ['gte' => 1000000, 'lte' => 2000000]));
62
        $expectedQuery->addShould(new Range('price_web_us', ['gte' => 4000000, 'lte' => 5000000]));
63
        $this->getQuery($selectedHistograms)->shouldBeLike($expectedQuery);
0 ignored issues
show
Bug introduced by
The method getQuery() does not exist on spec\BitBag\SyliusElasti...in\Facet\PriceFacetSpec. 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

63
        $this->/** @scrutinizer ignore-call */ 
64
               getQuery($selectedHistograms)->shouldBeLike($expectedQuery);
Loading history...
64
    }
65
66
    function it_returns_money_formatted_bucket_label(
67
        MoneyFormatterInterface $moneyFormatter,
68
        ShopperContextInterface $shopperContext
69
    ) {
70
        $shopperContext->getCurrencyCode()->willReturn('USD');
71
        $shopperContext->getLocaleCode()->willReturn('en_US');
72
        $moneyFormatter->format(1000000, 'USD', 'en_US')->shouldBeCalled()->willReturn('$10,000.00');
73
        $moneyFormatter->format(2000000, 'USD', 'en_US')->shouldBeCalled()->willReturn('$20,000.00');
74
75
        $this->getBucketLabel(['key' => 1000000, 'doc_count' => 6])->shouldBe('$10,000.00 - $20,000.00 (6)');
0 ignored issues
show
Bug introduced by
The method getBucketLabel() does not exist on spec\BitBag\SyliusElasti...in\Facet\PriceFacetSpec. 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

75
        $this->/** @scrutinizer ignore-call */ 
76
               getBucketLabel(['key' => 1000000, 'doc_count' => 6])->shouldBe('$10,000.00 - $20,000.00 (6)');
Loading history...
76
    }
77
}
78