Completed
Push — 1.0-adjust-cs ( dde5cf )
by Kamil
27:56
created

OptionsParserSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 69
rs 10
c 0
b 0
f 0

5 Methods

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