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

ShopProductListDataHandlerSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
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\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(
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...
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
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...
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);
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->retrieveData([
0 ignored issues
show
Bug introduced by
The method retrieveData() does not exist on spec\BitBag\SyliusElasti...ductListDataHandlerSpec. 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
               retrieveData([
Loading history...
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