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

TaxonFacetSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A it_implements_facet_interface() 0 3 1
A it_returns_taxon_name_as_bucket_label() 0 8 1
A it_returns_taxon_terms_aggregation() 0 6 1
A let() 0 3 1
A it_is_initializable() 0 3 1
A it_returns_bucket_key_as_bucket_label_if_taxon_could_not_be_found() 0 5 1
A it_returns_terms_query_for_selected_buckets() 0 4 1
1
<?php
2
3
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
4
5
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
6
use BitBag\SyliusElasticsearchPlugin\Facet\TaxonFacet;
7
use Elastica\Aggregation\Terms;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
use Sylius\Component\Core\Model\Taxon;
11
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
12
13
class TaxonFacetSpec extends ObjectBehavior
14
{
15
    private $taxonsProperty = 'product_taxons';
16
17
    function let(TaxonRepositoryInterface $taxonRepository)
18
    {
19
        $this->beConstructedWith($taxonRepository, $this->taxonsProperty);
20
    }
21
22
    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...
23
    {
24
        $this->shouldHaveType(TaxonFacet::class);
25
    }
26
27
    function it_implements_facet_interface()
28
    {
29
        $this->shouldHaveType(FacetInterface::class);
30
    }
31
32
    function it_returns_taxon_terms_aggregation()
33
    {
34
        $expectedAggregation = new Terms('taxon');
35
        $expectedAggregation->setField('product_taxons.keyword');
36
37
        $this->getAggregation()->shouldBeLike($expectedAggregation);
0 ignored issues
show
Bug introduced by
The method getAggregation() does not exist on spec\BitBag\SyliusElasti...in\Facet\TaxonFacetSpec. 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

37
        $this->/** @scrutinizer ignore-call */ 
38
               getAggregation()->shouldBeLike($expectedAggregation);
Loading history...
38
    }
39
40
    function it_returns_terms_query_for_selected_buckets()
41
    {
42
        $this->getQuery(['taxon_1', 'taxon_2'])->shouldBeLike(
0 ignored issues
show
Bug introduced by
The method getQuery() does not exist on spec\BitBag\SyliusElasti...in\Facet\TaxonFacetSpec. 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

42
        $this->/** @scrutinizer ignore-call */ 
43
               getQuery(['taxon_1', 'taxon_2'])->shouldBeLike(
Loading history...
43
            new \Elastica\Query\Terms('product_taxons.keyword', ['taxon_1', 'taxon_2'])
44
        );
45
    }
46
47
    function it_returns_taxon_name_as_bucket_label(TaxonRepositoryInterface $taxonRepository)
48
    {
49
        $taxon = new Taxon();
50
        $taxon->setCurrentLocale('en_US');
51
        $taxon->setName('Taxon 1');
52
        $taxonRepository->findOneBy(['code' => 'taxon_1'])->shouldBeCalled()->willReturn($taxon);
53
54
        $this->getBucketLabel(['key' => 'taxon_1', 'doc_count' => 3])->shouldBe('Taxon 1 (3)');
0 ignored issues
show
Bug introduced by
The method getBucketLabel() does not exist on spec\BitBag\SyliusElasti...in\Facet\TaxonFacetSpec. 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

54
        $this->/** @scrutinizer ignore-call */ 
55
               getBucketLabel(['key' => 'taxon_1', 'doc_count' => 3])->shouldBe('Taxon 1 (3)');
Loading history...
55
    }
56
57
    function it_returns_bucket_key_as_bucket_label_if_taxon_could_not_be_found(TaxonRepositoryInterface $taxonRepository)
58
    {
59
        $taxonRepository->findOneBy(['code' => 'taxon_1'])->shouldBeCalled()->willReturn(null);
60
61
        $this->getBucketLabel(['key' => 'taxon_1', 'doc_count' => 3])->shouldBe('taxon_1 (3)');
62
    }
63
}
64