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() |
|
|
|
|
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); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_returns_terms_query_for_selected_buckets() |
41
|
|
|
{ |
42
|
|
|
$this->getQuery(['taxon_1', 'taxon_2'])->shouldBeLike( |
|
|
|
|
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)'); |
|
|
|
|
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
|
|
|
|
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.