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
|
|
|
|