13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Bundle \FrameworkBundle \DependencyInjection \Compiler \FormPass ;
16
- use Symfony \Component \DependencyInjection \Argument \IteratorArgument ;
17
- use Symfony \Component \DependencyInjection \Argument \ServiceClosureArgument ;
18
16
use Symfony \Component \DependencyInjection \ContainerBuilder ;
19
17
use Symfony \Component \DependencyInjection \Definition ;
20
18
use Symfony \Component \DependencyInjection \Reference ;
21
- use Symfony \Component \DependencyInjection \ServiceLocator ;
22
19
use Symfony \Component \Form \AbstractType ;
23
20
24
21
/**
@@ -30,7 +27,8 @@ class FormPassTest extends TestCase
30
27
{
31
28
public function testDoNothingIfFormExtensionNotLoaded ()
32
29
{
33
- $ container = $ this ->createContainerBuilder ();
30
+ $ container = new ContainerBuilder ();
31
+ $ container ->addCompilerPass (new FormPass ());
34
32
35
33
$ container ->compile ();
36
34
@@ -39,33 +37,47 @@ public function testDoNothingIfFormExtensionNotLoaded()
39
37
40
38
public function testAddTaggedTypes ()
41
39
{
42
- $ container = $ this ->createContainerBuilder ();
40
+ $ container = new ContainerBuilder ();
41
+ $ container ->addCompilerPass (new FormPass ());
43
42
44
- $ container ->setDefinition ('form.extension ' , $ this ->createExtensionDefinition ());
43
+ $ extDefinition = new Definition ('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension ' );
44
+ $ extDefinition ->setArguments (array (
45
+ new Reference ('service_container ' ),
46
+ array (),
47
+ array (),
48
+ array (),
49
+ ));
50
+
51
+ $ container ->setDefinition ('form.extension ' , $ extDefinition );
45
52
$ container ->register ('my.type1 ' , __CLASS__ .'_Type1 ' )->addTag ('form.type ' );
46
53
$ container ->register ('my.type2 ' , __CLASS__ .'_Type2 ' )->addTag ('form.type ' );
47
54
48
55
$ container ->compile ();
49
56
50
57
$ extDefinition = $ container ->getDefinition ('form.extension ' );
51
58
52
- $ this ->assertEquals (
53
- (new Definition (ServiceLocator::class, array (array (
54
- __CLASS__ .'_Type1 ' => new ServiceClosureArgument (new Reference ('my.type1 ' )),
55
- __CLASS__ .'_Type2 ' => new ServiceClosureArgument (new Reference ('my.type2 ' )),
56
- ))))->addTag ('container.service_locator ' )->setPublic (false ),
57
- $ extDefinition ->getArgument (0 )
58
- );
59
+ $ this ->assertEquals (array (
60
+ __CLASS__ .'_Type1 ' => 'my.type1 ' ,
61
+ __CLASS__ .'_Type2 ' => 'my.type2 ' ,
62
+ ), $ extDefinition ->getArgument (1 ));
59
63
}
60
64
61
65
/**
62
66
* @dataProvider addTaggedTypeExtensionsDataProvider
63
67
*/
64
68
public function testAddTaggedTypeExtensions (array $ extensions , array $ expectedRegisteredExtensions )
65
69
{
66
- $ container = $ this ->createContainerBuilder ();
70
+ $ container = new ContainerBuilder ();
71
+ $ container ->addCompilerPass (new FormPass ());
67
72
68
- $ container ->setDefinition ('form.extension ' , $ this ->createExtensionDefinition ());
73
+ $ extDefinition = new Definition ('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension ' , array (
74
+ new Reference ('service_container ' ),
75
+ array (),
76
+ array (),
77
+ array (),
78
+ ));
79
+
80
+ $ container ->setDefinition ('form.extension ' , $ extDefinition );
69
81
70
82
foreach ($ extensions as $ serviceId => $ tag ) {
71
83
$ container ->register ($ serviceId , 'stdClass ' )->addTag ('form.type_extension ' , $ tag );
@@ -74,7 +86,7 @@ public function testAddTaggedTypeExtensions(array $extensions, array $expectedRe
74
86
$ container ->compile ();
75
87
76
88
$ extDefinition = $ container ->getDefinition ('form.extension ' );
77<
F438
/code>
- $ this ->assertEquals ($ expectedRegisteredExtensions , $ extDefinition ->getArgument (1 ));
89
+ $ this ->assertSame ($ expectedRegisteredExtensions , $ extDefinition ->getArgument (2 ));
78
90
}
79
91
80
92
/**
@@ -90,11 +102,8 @@ public function addTaggedTypeExtensionsDataProvider()
90
102
'my.type_extension3 ' => array ('extended_type ' => 'type2 ' ),
91
103
),
92
104
array (
93
- 'type1 ' => new IteratorArgument (array (
94
- new Reference ('my.type_extension1 ' ),
95
- new Reference ('my.type_extension2 ' ),
96
- )),
97
- 'type2 ' => new IteratorArgument (array (new Reference ('my.type_extension3 ' ))),
105
+ 'type1 ' => array ('my.type_extension1 ' , 'my.type_extension2 ' ),
106
+ 'type2 ' => array ('my.type_extension3 ' ),
98
107
),
99
108
),
100
109
array (
@@ -107,16 +116,8 @@ public function addTaggedTypeExtensionsDataProvider()
107
116
'my.type_extension6 ' => array ('extended_type ' => 'type2 ' , 'priority ' => 1 ),
108
117
),
109
118
array (
110
- 'type1 ' => new IteratorArgument (array (
111
- new Reference ('my.type_extension2 ' ),
112
- new Reference ('my.type_extension1 ' ),
113
- new Reference ('my.type_extension3 ' ),
114
- )),
115
- 'type2 ' => new IteratorArgument (array (
116
- new Reference ('my.type_extension4 ' ),
117
- new Reference ('my.type_extension5 ' ),
118
- new Reference ('my.type_extension6 ' ),
119
- )),
119
+ 'type1 ' => array ('my.type_extension2 ' , 'my.type_extension1 ' , 'my.type_extension3 ' ),
120
+ 'type2 ' => array ('my.type_extension4 ' , 'my.type_extension5 ' , 'my.type_extension6 ' ),
120
121
),
121
122
),
122
123
);
@@ -128,9 +129,17 @@ public function addTaggedTypeExtensionsDataProvider()
128
129
*/
129
130
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttribute ()
130
131
{
131
- $ container = $ this ->createContainerBuilder ();
132
+ $ container = new ContainerBuilder ();
133
+ $ container ->addCompilerPass (new FormPass ());
134
+
135
+ $ extDefinition = new Definition ('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension ' , array (
136
+ new Reference ('service_container ' ),
137
+ array (),
138
+ array (),
139
+ array (),
140
+ ));
132
141
133
- $ container ->setDefinition ('form.extension ' , $ this -> createExtensionDefinition () );
142
+ $ container ->setDefinition ('form.extension ' , $ extDefinition );
134
143
$ container ->register ('my.type_extension ' , 'stdClass ' )
135
144
->addTag ('form.type_extension ' );
136
145
@@ -139,102 +148,67 @@ public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttribute()
139
148
140
149
public function testAddTaggedGuessers ()
141
150
{
142
- $ container = $ this ->createContainerBuilder ();
151
+ $ container = new ContainerBuilder ();
152
+ $ container ->addCompilerPass (new FormPass ());
153
+
154
+ $ extDefinition = new Definition ('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension ' );
155
+ $ extDefinition ->setArguments (array (
156
+ new Reference ('service_container ' ),
157
+ array (),
158
+ array (),
159
+ array (),
160
+ ));
143
161
144
162
$ definition1 = new Definition ('stdClass ' );
145
163
$ definition1 ->addTag ('form.type_guesser ' );
146
164
$ definition2 = new Definition ('stdClass ' );
147
165
$ definition2 ->addTag ('form.type_guesser ' );
148
166
149
- $ container ->setDefinition ('form.extension ' , $ this -> createExtensionDefinition () );
167
+ $ container ->setDefinition ('form.extension ' , $ extDefinition );
150
168
$ container ->setDefinition ('my.guesser1 ' , $ definition1 );
151
169
$ container ->setDefinition ('my.guesser2 ' , $ definition2 );
152
170
153
171
$ container ->compile ();
154
172
155
173
$ extDefinition = $ container ->getDefinition ('form.extension ' );
156
174
157
- $ this ->assertEquals (
158
- new IteratorArgument (array (
159
- new Reference ('my.guesser1 ' ),
160
- new Reference ('my.guesser2 ' ),
161
- )),
162
- $ extDefinition ->getArgument (2 )
163
- );
175
+ $ this ->assertSame (array (
176
+ 'my.guesser1 ' ,
177
+ 'my.guesser2 ' ,
178
+ ), $ extDefinition ->getArgument (3 ));
164
179
}
165
180
166
181
/**
167
182
* @dataProvider privateTaggedServicesProvider
168
183
*/
169
- public function testPrivateTaggedServices ($ id , $ tagName, callable $ assertion , array $ tagAttributes = array () )
184
+ public function testPrivateTaggedServices ($ id , $ tagName )
170
185
{
171
- $ formPass = new FormPass ();
172
186
$ container = new ContainerBuilder ();
187
+ $ container ->addCompilerPass (new FormPass ());
173
188
174
- $ container ->setDefinition ('form.extension ' , $ this ->createExtensionDefinition ());
175
- $ container ->register ($ id , 'stdClass ' )->setPublic (false )->addTag ($ tagName , $ tagAttributes );
189
+ $ extDefinition = new Definition ('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension ' );
190
+ $ extDefinition ->setArguments (array (
191
+ new Reference ('service_container ' ),
192
+ array (),
193
+ array (),
194
+ array (),
195
+ ));
176
196
177
- $ formPass ->process ($ container );
197
+ $ container ->setDefinition ('form.extension ' , $ extDefinition );
198
+ $ container ->register ($ id , 'stdClass ' )->setPublic (false )->addTag ($ tagName , array ('extended_type ' => 'Foo ' ));
178
199
179
- $ assertion ($ container );
200
+ $ container ->compile ();
201
+ $ this ->assertTrue ($ container ->getDefinition ($ id )->isPublic ());
180
202
}
181
203
182
204
public function privateTaggedServicesProvider ()
183
205
{
184
206
return array (
185
- array (
186
- 'my.type ' ,
187
- 'form.type ' ,
188
- function (ContainerBuilder $ container ) {
189
- $ formTypes = $ container ->getDefinition ('form.extension ' )->getArgument (0 );
190
-
191
- $ this ->assertInstanceOf (Reference::class, $ formTypes );
192
-
193
- $ locator = $ container ->getDefinition ((string ) $ formTypes );
194
- $ expectedLocatorMap = array (
195
- 'stdClass ' => new ServiceClosureArgument (new Reference ('my.type ' )),
196
- );
197
-
198
- $ this ->assertInstanceOf (Definition::class, $ locator );
199
- $ this ->assertEquals ($ expectedLocatorMap , $ locator ->getArgument (0 ));
200
- },
201
- ),
202
- array (
203
- 'my.type_extension ' ,
204
- 'form.type_extension ' ,
205
- function (ContainerBuilder $ container ) {
206
- $ this ->assertEquals (
207
- array ('Symfony\Component\Form\Extension\Core\Type\FormType ' => new IteratorArgument (array (new Reference ('my.type_extension ' )))),
208
- $ container ->getDefinition ('form.extension ' )->getArgument (1 )
209
- );
210
- },
211
- array ('extended_type ' => 'Symfony\Component\Form\Extension\Core\Type\FormType ' ),
212
- ),
213
- array ('my.guesser ' , 'form.type_guesser ' , function (ContainerBuilder $ container ) {
214
- $ this ->assertEquals (new IteratorArgument (array (new Reference ('my.guesser ' ))), $ container ->getDefinition ('form.extension ' )->getArgument (2 ));
215
- }),
207
+ array ('my.type ' , 'form.type ' ),
208
+ array ('my.type_extension ' , 'form.type_extension ' ),
209
+ array ('my.guesser ' , 'form.type_guesser ' ),
216
210
);
217
211
}
218
-
219
- private function createContainerBuilder ()
220
- {
221
- $ container = new ContainerBuilder ();
222
- $ container ->addCompilerPass (new FormPass ());
223
-
224
- return $ container ;
225
- }
226
-
227
- private function createExtensionDefinition ()
228
- {
229
- $ definition = new Definition ('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension ' );
230
<
17AE
td data-grid-cell-id="diff-927b7d71ff1496a5960fd53e36ee4775be4c5fad59d526288908bb55162ca588-230-211-2" data-line-anchor="diff-927b7d71ff1496a5960fd53e36ee4775be4c5fad59d526288908bb55162ca588L230" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionLine-bgColor, var(--diffBlob-deletion-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell left-side-diff-cell border-right left-side">- $ definition ->setArguments (array (
231
- array (),
232
- array (),
233
- new IteratorArgument (array ()),
234
- ));
235
-
236
- return $ definition ;
237
- }
238
212
}
239
213
240
214
class FormPassTest_Type1 extends AbstractType
0 commit comments