|
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( |
|
|
|
|
|
|
20
|
|
|
ConcatedNameResolverInterface $attributeNameResolver, |
|
21
|
|
|
RepositoryInterface $attributeRepository |
|
22
|
|
|
): void { |
|
23
|
|
|
$attributeNameResolver->resolvePropertyName('attribute_code')->willReturn('attribute_attribute_code'); |
|
24
|
|
|
$this->beConstructedWith($attributeNameResolver, $attributeRepository, 'attribute_code'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function it_is_initializable(): void |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$this->shouldHaveType(AttributeFacet::class); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_implements_facet_interface(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->shouldHaveType(FacetInterface::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function it_returns_terms_aggregation(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$expectedAggregation = new Terms(''); |
|
40
|
|
|
$expectedAggregation->setField('attribute_attribute_code.keyword'); |
|
41
|
|
|
|
|
42
|
|
|
$this->getAggregation()->shouldBeLike($expectedAggregation); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function it_returns_terms_query(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$selectedBuckets = ['selected_value']; |
|
48
|
|
|
$expectedQuery = new \Elastica\Query\Terms('attribute_attribute_code.keyword', $selectedBuckets); |
|
49
|
|
|
|
|
50
|
|
|
$this->getQuery($selectedBuckets)->shouldBeLike($expectedQuery); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_returns_bucket_label_(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->getBucketLabel(['key' => 'value_label', 'doc_count' => 3])->shouldReturn('Value Label (3)'); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.