Completed
Push — master ( b70f30...259e2d )
by Kamil
32:06
created

it_creates_configuration_with_default_settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 15
nc 1
nop 5
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Bundle\ResourceBundle\Controller;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\ResourceBundle\Controller\ParametersParser;
16
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
17
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactory;
18
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
19
use Sylius\Component\Resource\Metadata\MetadataInterface;
20
use Symfony\Component\HttpFoundation\ParameterBag;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * @mixin RequestConfigurationFactory
25
 *
26
 * @author Arnaud Langade <[email protected]>
27
 * @author Paweł Jędrzejewski <[email protected]>
28
 */
29
class RequestConfigurationFactorySpec extends ObjectBehavior
30
{
31
    function let(ParametersParser $parametersParser)
32
    {
33
        $this->beConstructedWith($parametersParser, RequestConfiguration::class);
34
    }
35
36
    function it_is_initializable()
37
    {
38
        $this->shouldHaveType('Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactory');
39
    }
40
41
    function it_implements_request_configuration_factory_interface()
42
    {
43
        $this->shouldImplement(RequestConfigurationFactoryInterface::class);
44
    }
45
46
    function it_creates_configuration_from_resource_metadata_and_request(
47
        MetadataInterface $metadata,
48
        Request $request,
49
        ParametersParser $parametersParser,
50
        ParameterBag $headersBag,
51
        ParameterBag $attributesBag
52
    ) {
53
        $request->headers = $headersBag;
0 ignored issues
show
Documentation Bug introduced by
It seems like $headersBag of type object<Symfony\Component...oundation\ParameterBag> is incompatible with the declared type object<Symfony\Component...tpFoundation\HeaderBag> of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
        $request->attributes = $attributesBag;
55
56
        $headersBag->has('Accept')->willReturn(false);
57
58
        $configuration = ['template' => ':Product:show.html.twig'];
59
60
        $attributesBag->get('_sylius', [])->willReturn($configuration);
61
        $parametersParser->parseRequestValues($configuration, $request)->willReturn($configuration);
62
63
        $this->create($metadata, $request)->shouldHaveType(RequestConfiguration::class);
64
    }
65
66
    function it_creates_configuration_without_default_settings(
67
        MetadataInterface $metadata,
68
        Request $request,
69
        ParametersParser $parametersParser,
70
        ParameterBag $headersBag,
71
        ParameterBag $attributesBag
72
    ) {
73
        $request->headers = $headersBag;
0 ignored issues
show
Documentation Bug introduced by
It seems like $headersBag of type object<Symfony\Component...oundation\ParameterBag> is incompatible with the declared type object<Symfony\Component...tpFoundation\HeaderBag> of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
        $request->attributes = $attributesBag;
75
76
        $configuration = ['template' => ':Product:list.html.twig'];
77
78
        $attributesBag->get('_sylius', [])->willReturn($configuration);
79
        $parametersParser->parseRequestValues($configuration, $request)->willReturn($configuration);
80
81
        $this->create($metadata, $request)->isSortable()->shouldReturn(false);
82
    }
83
84
    function it_creates_configuration_with_default_settings(
85
        MetadataInterface $metadata,
86
        Request $request,
87
        ParametersParser $parametersParser,
88
        ParameterBag $headersBag,
89
        ParameterBag $attributesBag
90
    ) {
91
        $defaultParameters = ['sortable' => true];
92
93
        $this->beConstructedWith($parametersParser, RequestConfiguration::class, $defaultParameters);
94
95
        $request->headers = $headersBag;
0 ignored issues
show
Documentation Bug introduced by
It seems like $headersBag of type object<Symfony\Component...oundation\ParameterBag> is incompatible with the declared type object<Symfony\Component...tpFoundation\HeaderBag> of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
96
        $request->attributes = $attributesBag;
97
98
        $configuration = ['template' => ':Product:list.html.twig'];
99
        $attributesBag->get('_sylius', [])->willReturn($configuration);
100
101
        $configuration = ['template' => ':Product:list.html.twig', 'sortable' => true];
102
        $parametersParser->parseRequestValues($configuration, $request)->willReturn($configuration);
103
104
        $this->create($metadata, $request)->isSortable()->shouldReturn(true);
105
    }
106
}
107