Passed
Pull Request — master (#5)
by
unknown
04:17
created

TaxonContextSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Symfony\Component\HttpFoundation\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $requestStack->getCurrentRequest()->/** @scrutinizer ignore-call */ willReturn($request);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
56
        $localeContext->getLocaleCode()->willReturn('en');
57
58
        $taxonRepository->findOneBySlug('book', 'en')->willReturn($taxon);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Taxonomy\Model\TaxonInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        $taxonRepository->findOneBySlug('book', 'en')->/** @scrutinizer ignore-call */ willReturn($taxon);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
60
        $this->getTaxon()->shouldBeEqualTo($taxon);
0 ignored issues
show
Bug introduced by
The method getTaxon() does not exist on spec\BitBag\SyliusElasti...ontext\TaxonContextSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        $this->/** @scrutinizer ignore-call */ 
61
               getTaxon()->shouldBeEqualTo($taxon);
Loading history...
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