1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler; |
6
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryBuildingPass; |
8
|
|
|
use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryRegistrationPass; |
9
|
|
|
use Knp\DictionaryBundle\Dictionary; |
10
|
|
|
use Knp\DictionaryBundle\Dictionary\Factory\Aggregate; |
11
|
|
|
use PhpSpec\ObjectBehavior; |
12
|
|
|
use Prophecy\Argument; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Webmozart\Assert\Assert; |
15
|
|
|
|
16
|
|
|
final class DictionaryBuildingPassSpec extends ObjectBehavior |
17
|
|
|
{ |
18
|
|
|
function it_is_initializable() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$this->shouldHaveType(DictionaryBuildingPass::class); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $container) |
24
|
|
|
{ |
25
|
|
|
$config = [ |
26
|
|
|
'dictionaries' => [ |
27
|
|
|
'dico1' => [ |
28
|
|
|
'type' => Dictionary::VALUE_AS_KEY, |
29
|
|
|
'content' => ['foo', 'bar', 'baz'], |
30
|
|
|
], |
31
|
|
|
], |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
$container->getParameter('knp_dictionary.configuration')->willReturn($config); |
|
|
|
|
35
|
|
|
$container->setDefinition( |
36
|
|
|
'knp_dictionary.dictionary.dico1', |
37
|
|
|
Argument::that(function ($definition): bool { |
|
|
|
|
38
|
|
|
Assert::eq($definition->getClass(), Dictionary::class); |
39
|
|
|
|
40
|
|
|
$factory = $definition->getFactory(); |
41
|
|
|
|
42
|
|
|
Assert::eq((string) $factory[0], Aggregate::class); |
43
|
|
|
|
44
|
|
|
Assert::eq($factory[1], 'create'); |
45
|
|
|
|
46
|
|
|
Assert::eq( |
47
|
|
|
$definition->getArguments(), |
48
|
|
|
[ |
49
|
|
|
'dico1', |
50
|
|
|
[ |
51
|
|
|
'type' => Dictionary::VALUE_AS_KEY, |
52
|
|
|
'content' => ['foo', 'bar', 'baz'], |
53
|
|
|
], |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
Assert::eq( |
58
|
|
|
$definition->getTags(), |
59
|
|
|
[DictionaryRegistrationPass::TAG_DICTIONARY => [[]]] |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
}) |
64
|
|
|
)->shouldBeCalled(); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->process($container); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $container) |
70
|
|
|
{ |
71
|
|
|
$config = [ |
72
|
|
|
'dictionaries' => [ |
73
|
|
|
'dico1' => [ |
74
|
|
|
'type' => Dictionary::VALUE, |
75
|
|
|
'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], |
76
|
|
|
], |
77
|
|
|
], |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$container->getParameter('knp_dictionary.configuration')->willReturn($config); |
81
|
|
|
$container->setDefinition( |
82
|
|
|
'knp_dictionary.dictionary.dico1', |
83
|
|
|
Argument::that(function ($definition): bool { |
|
|
|
|
84
|
|
|
Assert::eq($definition->getClass(), Dictionary::class); |
85
|
|
|
|
86
|
|
|
$factory = $definition->getFactory(); |
87
|
|
|
|
88
|
|
|
Assert::eq((string) $factory[0], Aggregate::class); |
89
|
|
|
|
90
|
|
|
Assert::eq($factory[1], 'create'); |
91
|
|
|
|
92
|
|
|
Assert::eq( |
93
|
|
|
$definition->getArguments(), |
94
|
|
|
[ |
95
|
|
|
'dico1', |
96
|
|
|
[ |
97
|
|
|
'type' => Dictionary::VALUE, |
98
|
|
|
'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], |
99
|
|
|
], |
100
|
|
|
] |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
Assert::eq($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); |
104
|
|
|
|
105
|
|
|
return true; |
106
|
|
|
}) |
107
|
|
|
)->shouldBeCalled(); |
108
|
|
|
|
109
|
|
|
$this->process($container); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
function it_builds_a_key_value_dictionary_from_the_config(ContainerBuilder $container) |
113
|
|
|
{ |
114
|
|
|
$config = [ |
115
|
|
|
'dictionaries' => [ |
116
|
|
|
'dico1' => [ |
117
|
|
|
'type' => Dictionary::KEY_VALUE, |
118
|
|
|
'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], |
119
|
|
|
], |
120
|
|
|
], |
121
|
|
|
]; |
122
|
|
|
|
123
|
|
|
$container->getParameter('knp_dictionary.configuration')->willReturn($config); |
124
|
|
|
$container->setDefinition( |
125
|
|
|
'knp_dictionary.dictionary.dico1', |
126
|
|
|
Argument::that(function ($definition): bool { |
|
|
|
|
127
|
|
|
Assert::eq($definition->getClass(), Dictionary::class); |
128
|
|
|
|
129
|
|
|
$factory = $definition->getFactory(); |
130
|
|
|
|
131
|
|
|
Assert::eq((string) $factory[0], Aggregate::class); |
132
|
|
|
|
133
|
|
|
Assert::eq($factory[1], 'create'); |
134
|
|
|
|
135
|
|
|
Assert::eq( |
136
|
|
|
$definition->getArguments(), |
137
|
|
|
[ |
138
|
|
|
'dico1', |
139
|
|
|
[ |
140
|
|
|
'type' => Dictionary::KEY_VALUE, |
141
|
|
|
'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], |
142
|
|
|
], |
143
|
|
|
] |
144
|
|
|
); |
145
|
|
|
|
146
|
|
|
Assert::eq($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); |
147
|
|
|
|
148
|
|
|
return true; |
149
|
|
|
}) |
150
|
|
|
)->shouldBeCalled(); |
151
|
|
|
|
152
|
|
|
$this->process($container); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.