Completed
Push — symfony3 ( 1143df...c57be8 )
by Kamil
18:42
created

OptionsParserSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 74
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_is_initializable() 0 4 1
A it_is_an_options_parser() 0 4 1
A it_parses_options() 0 9 1
B it_parses_options_with_expression() 0 30 1
A it_parses_options_with_parameter_from_resource() 0 12 1
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\Grid\Parser;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParser;
16
use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface;
17
use Sylius\Component\Resource\Model\ResourceInterface;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
22
23
/**
24
 * @author Grzegorz Sadowski <[email protected]>
25
 */
26
final class OptionsParserSpec extends ObjectBehavior
27
{
28
    function let(
29
        ContainerInterface $container,
30
        ExpressionLanguage $expression,
31
        PropertyAccessorInterface $propertyAccessor
32
    ) {
33
        $this->beConstructedWith($container, $expression, $propertyAccessor);
34
    }
35
36
    function it_is_initializable()
37
    {
38
        $this->shouldHaveType(OptionsParser::class);
39
    }
40
41
    function it_is_an_options_parser()
42
    {
43
        $this->shouldImplement(OptionsParserInterface::class);
44
    }
45
46
    function it_parses_options(Request $request)
47
    {
48
        $request->get('id')->willReturn(7);
49
50
        $this
51
            ->parseOptions(['id' => '$id'], $request)
52
            ->shouldReturn(['id' => 7])
53
        ;
54
    }
55
56
    function it_parses_options_with_expression(
57
        ContainerInterface $container,
58
        ExpressionLanguage $expression,
59
        Request $request
60
    ) {
61
        $expression->evaluate('service("demo_service")', ['container' => $container])->willReturn('demo_object');
62
63
        $this
64
            ->parseOptions(
65
                [
66
                    'factory' => [
67
                        'method' => 'createByParameter',
68
                        'arguments' => [
69
                            'expr:service("demo_service")',
70
                        ],
71
                    ],
72
                ],
73
                $request
74
            )
75
            ->shouldReturn(
76
                [
77
                    'factory' => [
78
                        'method' => 'createByParameter',
79
                        'arguments' => [
80
                            'demo_object',
81
                        ],
82
                    ],
83
                ]
84
        );
85
    }
86
87
    function it_parses_options_with_parameter_from_resource(
88
        PropertyAccessorInterface $propertyAccessor,
89
        Request $request,
90
        ResourceInterface $data
91
    ) {
92
        $propertyAccessor->getValue($data, 'id')->willReturn(21);
93
94
        $this
95
            ->parseOptions(['id' => 'resource.id'], $request, $data)
96
            ->shouldReturn(['id' => 21])
97
        ;
98
    }
99
}
100