Passed
Push — master ( cc4e78...1262d4 )
by Damian
04:08
created

TaxonFacetSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 50
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 6 1
A it_returns_terms_query_for_selected_buckets() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
6
7
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
8
use BitBag\SyliusElasticsearchPlugin\Facet\TaxonFacet;
9
use Elastica\Aggregation\Terms;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
use Sylius\Component\Core\Model\Taxon;
13
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
14
15
final class TaxonFacetSpec extends ObjectBehavior
16
{
17
    private $taxonsProperty = 'product_taxons';
18
19
    function let(TaxonRepositoryInterface $taxonRepository): void
20
    {
21
        $this->beConstructedWith($taxonRepository, $this->taxonsProperty);
22
    }
23
24
    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...
25
    {
26
        $this->shouldHaveType(TaxonFacet::class);
27
    }
28
29
    function it_implements_facet_interface(): void
30
    {
31
        $this->shouldHaveType(FacetInterface::class);
32
    }
33
34
    function it_returns_taxon_terms_aggregation(): void
35
    {
36
        $expectedAggregation = new Terms('taxon');
37
        $expectedAggregation->setField('product_taxons.keyword');
38
39
        $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

39
        $this->/** @scrutinizer ignore-call */ 
40
               getAggregation()->shouldBeLike($expectedAggregation);
Loading history...
40
    }
41
42
    function it_returns_terms_query_for_selected_buckets(): void
43
    {
44
        $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

44
        $this->/** @scrutinizer ignore-call */ 
45
               getQuery(['taxon_1', 'taxon_2'])->shouldBeLike(
Loading history...
45
            new \Elastica\Query\Terms('product_taxons.keyword', ['taxon_1', 'taxon_2'])
46
        );
47
    }
48
49
    function it_returns_taxon_name_as_bucket_label(TaxonRepositoryInterface $taxonRepository): void
50
    {
51
        $taxon = new Taxon();
52
        $taxon->setCurrentLocale('en_US');
53
        $taxon->setName('Taxon 1');
54
        $taxonRepository->findOneBy(['code' => 'taxon_1'])->shouldBeCalled()->willReturn($taxon);
55
56
        $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

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