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\Context; |
||
14 | |||
15 | use BitBag\SyliusElasticsearchPlugin\Context\TaxonContext; |
||
16 | use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface; |
||
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 | use Symfony\Component\HttpFoundation\Request; |
||
23 | use Symfony\Component\HttpFoundation\RequestStack; |
||
24 | |||
25 | final class TaxonContextSpec extends ObjectBehavior |
||
26 | { |
||
27 | function let( |
||
0 ignored issues
–
show
|
|||
28 | RequestStack $requestStack, |
||
29 | TaxonRepositoryInterface $taxonRepository, |
||
30 | LocaleContextInterface $localeContext |
||
31 | ): void { |
||
32 | $this->beConstructedWith($requestStack, $taxonRepository, $localeContext); |
||
33 | } |
||
34 | |||
35 | function it_is_initializable(): void |
||
0 ignored issues
–
show
|
|||
36 | { |
||
37 | $this->shouldHaveType(TaxonContext::class); |
||
38 | } |
||
39 | |||
40 | function it_implements_taxon_context_interface(): void |
||
41 | { |
||
42 | $this->shouldHaveType(TaxonContextInterface::class); |
||
43 | } |
||
44 | |||
45 | function it_gets_taxon( |
||
46 | RequestStack $requestStack, |
||
47 | TaxonRepositoryInterface $taxonRepository, |
||
48 | LocaleContextInterface $localeContext, |
||
49 | Request $request, |
||
50 | TaxonInterface $taxon |
||
51 | ): void { |
||
52 | $request->get('slug')->willReturn('book'); |
||
53 | |||
54 | $requestStack->getCurrentRequest()->willReturn($request); |
||
55 | |||
56 | $localeContext->getLocaleCode()->willReturn('en'); |
||
57 | |||
58 | $taxonRepository->findOneBySlug('book', 'en')->willReturn($taxon); |
||
59 | |||
60 | $this->getTaxon()->shouldBeEqualTo($taxon); |
||
61 | } |
||
62 | |||
63 | function it_throws_taxon_not_found_exception_if_taxon_is_null( |
||
64 | RequestStack $requestStack, |
||
65 | TaxonRepositoryInterface $taxonRepository, |
||
66 | LocaleContextInterface $localeContext, |
||
67 | Request $request |
||
68 | ): void { |
||
69 | $request->get('slug')->willReturn('book'); |
||
70 | |||
71 | $requestStack->getCurrentRequest()->willReturn($request); |
||
72 | |||
73 | $localeContext->getLocaleCode()->willReturn('en'); |
||
74 | |||
75 | $taxonRepository->findOneBySlug('book', 'en')->willReturn(null); |
||
76 | |||
77 | $this->shouldThrow(TaxonNotFoundException::class)->during('getTaxon'); |
||
78 | } |
||
79 | } |
||
80 |
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.