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

ContainsNameQueryBuilderSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 5
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace spec\BitBag\SyliusElasticsearchPlugin\QueryBuilder;
14
15
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
16
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\ContainsNameQueryBuilder;
17
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
18
use Elastica\Query\Match;
19
use PhpSpec\ObjectBehavior;
20
use Sylius\Component\Locale\Context\LocaleContextInterface;
21
22
final class ContainsNameQueryBuilderSpec extends ObjectBehavior
23
{
24
    function let(
25
        LocaleContextInterface $localeContext,
26
        ConcatedNameResolverInterface $productNameNameResolver
27
    ): void {
28
        $this->beConstructedWith(
29
            $localeContext,
30
            $productNameNameResolver,
31
            'name_property'
32
        );
33
    }
34
35
    function it_is_initializable(): void
36
    {
37
        $this->shouldHaveType(ContainsNameQueryBuilder::class);
38
    }
39
40
    function it_implements_query_builder_interface(): void
41
    {
42
        $this->shouldHaveType(QueryBuilderInterface::class);
43
    }
44
45
    function it_builds_query(
46
        LocaleContextInterface $localeContext,
47
        ConcatedNameResolverInterface $productNameNameResolver
48
    ): void {
49
        $localeContext->getLocaleCode()->willReturn('en');
50
51
        $productNameNameResolver->resolvePropertyName('en')->willReturn('en');
52
53
        $this->buildQuery(['name_property' => 'Book'])->shouldBeAnInstanceOf(Match::class);
54
    }
55
56
    function it_builds_returned_null_if_property_is_null(
57
        LocaleContextInterface $localeContext,
58
        ConcatedNameResolverInterface $productNameNameResolver
59
    ): void {
60
        $localeContext->getLocaleCode()->willReturn('en');
61
62
        $productNameNameResolver->resolvePropertyName('en')->willReturn('en');
63
64
        $this->buildQuery(['name_property' => null])->shouldBeEqualTo(null);
65
    }
66
}
67