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

ShopProductListDataHandlerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 57
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\Controller\RequestDataHandler;
14
15
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\DataHandlerInterface;
16
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\ShopProductListDataHandler;
17
use BitBag\SyliusElasticsearchPlugin\Exception\TaxonNotFoundException;
18
use PhpSpec\ObjectBehavior;
19
use Sylius\Component\Core\Model\TaxonInterface;
20
use Sylius\Component\Locale\Context\LocaleContextInterface;
21
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
22
23
final class ShopProductListDataHandlerSpec extends ObjectBehavior
24
{
25
    function let(
26
        TaxonRepositoryInterface $taxonRepository,
27
        LocaleContextInterface $localeContext
28
    ): void {
29
        $this->beConstructedWith(
30
            $taxonRepository,
31
            $localeContext,
32
            'name',
33
            'taxons',
34
            'option',
35
            'attribute'
36
        );
37
    }
38
39
    function it_is_initializable(): void
40
    {
41
        $this->shouldHaveType(ShopProductListDataHandler::class);
42
    }
43
44
    function it_implements_data_handler_interface(): void
45
    {
46
        $this->shouldHaveType(DataHandlerInterface::class);
47
    }
48
49
    function it_retrieves_data(
50
        LocaleContextInterface $localeContext,
51
        TaxonRepositoryInterface $taxonRepository,
52
        TaxonInterface $taxon
53
    ): void {
54
        $localeContext->getLocaleCode()->willReturn('en');
55
56
        $taxon->getCode()->willReturn('book');
57
58
        $taxonRepository->findOneBySlug('book', 'en')->willReturn($taxon);
59
60
        $this->retrieveData([
61
            'slug' => 'book',
62
            'name' => 'Book',
63
            'price' => [],
64
        ])->shouldBeEqualTo([
65
            'name' => 'Book',
66
            'taxons' => 'book',
67
            'taxon' => $taxon,
68
        ]);
69
    }
70
71
    function it_throws_taxon_not_found_exception_if_taxon_is_null(
72
        LocaleContextInterface $localeContext,
73
        TaxonInterface $taxon
74
    ): void {
75
        $localeContext->getLocaleCode()->willReturn('en');
76
77
        $taxon->getCode()->willReturn('book');
78
79
        $this->shouldThrow(TaxonNotFoundException::class)->during('retrieveData', [['slug' => 'book']]);
80
    }
81
}
82