Passed
Push — master ( 979f6d...757493 )
by US
08:39 queued 11s
created

OptionFacetSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 7
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\OptionFacet;
9
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
10
use Elastica\Aggregation\Terms;
11
use PhpSpec\ObjectBehavior;
12
use Sylius\Component\Product\Model\ProductOption;
13
use Sylius\Component\Resource\Repository\RepositoryInterface;
14
15
final class OptionFacetSpec extends ObjectBehavior
16
{
17
    function let(ConcatedNameResolverInterface $optionNameResolver, RepositoryInterface $productOptionRepository): void
18
    {
19
        $optionCode = 'SUPPLY';
20
        $optionNameResolver->resolvePropertyName('SUPPLY')->willReturn('option_SUPPLY');
21
        $productOption = new ProductOption();
22
        $productOption->setCurrentLocale('en_US');
23
        $productOption->setName('Supply');
24
        $productOptionRepository->findOneBy(['code' => 'SUPPLY'])->willReturn($productOption);
25
        $this->beConstructedWith($optionNameResolver, $productOptionRepository, $optionCode);
26
    }
27
28
    function it_is_initializable(): void
29
    {
30
        $this->shouldHaveType(OptionFacet::class);
31
    }
32
33
    function it_implements_facet_interface(): void
34
    {
35
        $this->shouldHaveType(FacetInterface::class);
36
    }
37
38
    function it_returns_terms_aggregation(): void
39
    {
40
        $expectedAggregation = new Terms('');
41
        $expectedAggregation->setField('option_SUPPLY.keyword');
42
43
        $this->getAggregation()->shouldBeLike($expectedAggregation);
44
    }
45
46
    function it_returns_terms_query(): void
47
    {
48
        $expectedQuery = new \Elastica\Query\Terms('option_SUPPLY.keyword', ['selected', 'values']);
49
50
        $this->getQuery(['selected', 'values'])->shouldBeLike($expectedQuery);
51
    }
52
53
    function it_returns_bucket_label(): void
54
    {
55
        $this->getBucketLabel(['key' => 'option_value', 'doc_count' => 3])->shouldReturn('Option Value (3)');
56
    }
57
58
    function it_returns_option_name_as_facet_label(): void
59
    {
60
        $this->getLabel()->shouldReturn('Supply');
61
    }
62
}
63