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
|
|
|
final class OptionsParserSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function let( |
27
|
|
|
ContainerInterface $container, |
28
|
|
|
ExpressionLanguage $expression, |
29
|
|
|
PropertyAccessorInterface $propertyAccessor |
30
|
|
|
): void { |
31
|
|
|
$this->beConstructedWith($container, $expression, $propertyAccessor); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_is_an_options_parser(): void |
35
|
|
|
{ |
36
|
|
|
$this->shouldImplement(OptionsParserInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_parses_options(Request $request): void |
40
|
|
|
{ |
41
|
|
|
$request->get('id')->willReturn(7); |
42
|
|
|
|
43
|
|
|
$this |
44
|
|
|
->parseOptions(['id' => '$id'], $request) |
45
|
|
|
->shouldReturn(['id' => 7]) |
46
|
|
|
; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_parses_options_with_expression( |
50
|
|
|
ContainerInterface $container, |
51
|
|
|
ExpressionLanguage $expression, |
52
|
|
|
Request $request |
53
|
|
|
): void { |
54
|
|
|
$expression->evaluate('service("demo_service")', ['container' => $container])->willReturn('demo_object'); |
55
|
|
|
|
56
|
|
|
$this |
57
|
|
|
->parseOptions( |
58
|
|
|
[ |
59
|
|
|
'factory' => [ |
60
|
|
|
'method' => 'createByParameter', |
61
|
|
|
'arguments' => [ |
62
|
|
|
'expr:service("demo_service")', |
63
|
|
|
], |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
$request |
67
|
|
|
) |
68
|
|
|
->shouldReturn( |
69
|
|
|
[ |
70
|
|
|
'factory' => [ |
71
|
|
|
'method' => 'createByParameter', |
72
|
|
|
'arguments' => [ |
73
|
|
|
'demo_object', |
74
|
|
|
], |
75
|
|
|
], |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
function it_parses_options_with_parameter_from_resource( |
81
|
|
|
PropertyAccessorInterface $propertyAccessor, |
82
|
|
|
Request $request, |
83
|
|
|
ResourceInterface $data |
84
|
|
|
): void { |
85
|
|
|
$propertyAccessor->getValue($data, 'id')->willReturn(21); |
86
|
|
|
|
87
|
|
|
$this |
88
|
|
|
->parseOptions(['id' => 'resource.id'], $request, $data) |
89
|
|
|
->shouldReturn(['id' => 21]) |
90
|
|
|
; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|