@@ -86,6 +86,26 @@ public function testProcessValue()
86
86
$ this ->assertSame (CustomDefinition::class, \get_class ($ locator ('inlines.service ' )));
87
87
}
88
88
89
+ public function testServiceListIsOrdered ()
90
+ {
91
+ $ container = new ContainerBuilder ();
92
+
93
+ $ container ->register ('bar ' , CustomDefinition::class);
94
+ $ container ->register ('baz ' , CustomDefinition::class);
95
+
96
+ $ container ->register ('foo ' , ServiceLocator::class)
97
+ ->setArguments ([[
98
+ new Reference ('baz ' ),
99
+ new Reference ('bar ' ),
100
+ ]])
101
+ ->addTag ('container.service_locator ' )
102
+ ;
103
+
104
+ (new ServiceLocatorTagPass ())->process ($ container );
105
+
106
+ $ this ->assertSame (['bar ' , 'baz ' ], array_keys ($ container ->getDefinition ('foo ' )->getArgument (0 )));
107
+ }
108
+
89
109
public function testServiceWithKeyOverwritesPreviousInheritedKey ()
90
110
{
91
111
$ container = new ContainerBuilder ();
@@ -170,6 +190,27 @@ public function testTaggedServices()
170
190
$ this ->assertSame (TestDefinition2::class, $ locator ('baz ' )::class);
171
191
}
172
192
193
+ public function testTaggedServicesKeysAreKept ()
194
+ {
195
+ $ container = new ContainerBuilder ();
196
+
197
+ $ container ->register ('bar ' , TestDefinition1::class)->addTag ('test_tag ' , ['index ' => 0 ]);
198
+ $ container ->register ('baz ' , TestDefinition2::class)->addTag ('test_tag ' , ['index ' => 1 ]);
199
+
200
+ $ container ->register ('foo ' , ServiceLocator::class)
201
+ ->setArguments ([new TaggedIteratorArgument ('test_tag ' , 'index ' , null , true )])
202
+ ->addTag ('container.service_locator ' )
203
+ ;
204
+
205
+ (new ServiceLocatorTagPass ())->process ($ container );
206
+
207
+ /** @var ServiceLocator $locator */
208
+ $ locator = $ container ->get ('foo ' );
209
+
210
+ $ this ->assertSame (TestDefinition1::class, $ locator (0 )::class);
211
+ $ this ->assertSame (TestDefinition2::class, $ locator (1 )::class);
212
+ }
213
+
173
214
public function testIndexedByServiceIdWithDecoration ()
174
215
{
175
216
$ container = new ContainerBuilder ();
@@ -201,15 +242,33 @@ public function testIndexedByServiceIdWithDecoration()
201
242
static ::assertInstanceOf (DecoratedService::class, $ locator ->get (Service::class));
202
243
}
203
244
204
- public function testDefinitionOrderIsTheSame ()
245
+ public function testServicesKeysAreKept ()
205
246
{
206
247
$ container = new ContainerBuilder ();
207
248
$ container ->register ('service-1 ' );
208
249
$ container ->register ('service-2 ' );
250
+ $ container ->register ('service-3 ' );
209
251
210
252
$ locator = ServiceLocatorTagPass::register ($ container , [
211
- new Reference ('service-2 ' ),
212
253
new Reference ('service-1 ' ),
254
+ 'service-2 ' => new Reference ('service-2 ' ),
255
+ 'foo ' => new Reference ('service-3 ' ),
256
+ ]);
257
+ $ locator = $ container ->getDefinition ($ locator );
258
+ $ factories = $ locator ->getArguments ()[0 ];
259
+
260
+ static ::assertSame ([0 , 'service-2 ' , 'foo ' ], array_keys ($ factories ));
261
+ }
262
+
263
+ public function testDefinitionOrderIsTheSame ()
264
+ {
265
+ $ container = new ContainerBuilder ();
266
+ $ container ->register ('service-1 ' );
267
+ $ container ->register ('service-2 ' );
268
+
269
+ $ locator = ServiceLocatorTagPass::register ($ container , [
270
+ 'service-2 ' => new Reference ('service-2 ' ),
271
+ 'service-1 ' => new Reference ('service-1 ' ),
213
272
]);
214
273
$ locator = $ container ->getDefinition ($ locator );
215
274
$ factories = $ locator ->getArguments ()[0 ];
0 commit comments