Passed
Pull Request — master (#69)
by Manuele
04:40
created

AttributeFacetSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A it_returns_bucket_label_from_config_for_select_attribute() 0 8 1
A it_returns_human_readable_bucket_label_for_text_attribute() 0 7 1
A it_is_initializable() 0 3 1
A it_implements_facet_interface() 0 3 1
A it_returns_terms_query() 0 6 1
A let() 0 8 1
A it_returns_terms_aggregation() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
6
7
use BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet;
8
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
9
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
10
use Elastica\Aggregation\Terms;
11
use PhpSpec\ObjectBehavior;
12
use Prophecy\Argument;
13
use Sylius\Component\Attribute\Model\Attribute;
14
use Sylius\Component\Locale\Context\LocaleContextInterface;
15
use Sylius\Component\Resource\Repository\RepositoryInterface;
16
17
final class AttributeFacetSpec extends ObjectBehavior
18
{
19
    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...
20
        ConcatedNameResolverInterface $attributeNameResolver,
21
        RepositoryInterface $attributeRepository,
22
        LocaleContextInterface $localeContext
23
    ): void {
24
        $attributeNameResolver->resolvePropertyName('attribute_code')->willReturn('attribute_attribute_code');
25
        $localeContext->getLocaleCode()->willReturn('en_US');
26
        $this->beConstructedWith($attributeNameResolver, $attributeRepository, $localeContext, 'attribute_code');
27
    }
28
29
    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...
30
    {
31
        $this->shouldHaveType(AttributeFacet::class);
32
    }
33
34
    function it_implements_facet_interface(): void
35
    {
36
        $this->shouldHaveType(FacetInterface::class);
37
    }
38
39
    function it_returns_terms_aggregation(): void
40
    {
41
        $expectedAggregation = new Terms('');
42
        $expectedAggregation->setField('attribute_attribute_code.keyword');
43
44
        $this->getAggregation()->shouldBeLike($expectedAggregation);
0 ignored issues
show
Bug introduced by
The method getAggregation() does not exist on spec\BitBag\SyliusElasti...acet\AttributeFacetSpec. 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
               getAggregation()->shouldBeLike($expectedAggregation);
Loading history...
45
    }
46
47
    function it_returns_terms_query(): void
48
    {
49
        $selectedBuckets = ['selected_value'];
50
        $expectedQuery = new \Elastica\Query\Terms('attribute_attribute_code.keyword', $selectedBuckets);
51
52
        $this->getQuery($selectedBuckets)->shouldBeLike($expectedQuery);
0 ignored issues
show
Bug introduced by
The method getQuery() does not exist on spec\BitBag\SyliusElasti...acet\AttributeFacetSpec. 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
               getQuery($selectedBuckets)->shouldBeLike($expectedQuery);
Loading history...
53
    }
54
55
    function it_returns_bucket_label_from_config_for_select_attribute(RepositoryInterface $attributeRepository): void
56
    {
57
        $attribute = new Attribute();
58
        $attribute->setType('select');
59
        $attribute->setConfiguration(['choices' => ['value_id' => ['en_US' => 'Value Label']]]);
60
        $attributeRepository->findOneBy(['code' => 'attribute_code'])->willReturn($attribute);
61
62
        $this->getBucketLabel(['key' => 'value_id', 'doc_count' => 3])->shouldReturn('Value Label (3)');
0 ignored issues
show
Bug introduced by
The method getBucketLabel() does not exist on spec\BitBag\SyliusElasti...acet\AttributeFacetSpec. 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

62
        $this->/** @scrutinizer ignore-call */ 
63
               getBucketLabel(['key' => 'value_id', 'doc_count' => 3])->shouldReturn('Value Label (3)');
Loading history...
63
    }
64
65
    function it_returns_human_readable_bucket_label_for_text_attribute(RepositoryInterface $attributeRepository): void
66
    {
67
        $attribute = new Attribute();
68
        $attribute->setType('text');
69
        $attributeRepository->findOneBy(['code' => 'attribute_code'])->willReturn($attribute);
70
71
        $this->getBucketLabel(['key' => 'green_&_white', 'doc_count' => 3])->shouldReturn('Green & White (3)');
72
    }
73
}
74