@@ -151,34 +151,6 @@ public function testDelegatorsDoNotApplyToAliasResolvingToServiceEntry() : void
151
151
self ::assertSame ($ instance , $ container ->get ('foo-bar ' ));
152
152
}
153
153
154
- public function testDelegatorsDoNotTriggerForAliasTargetingFactoryBasedService () : void
155
- {
156
- $ config = [
157
- 'aliases ' => [
158
- 'alias ' => 'foo-bar ' ,
159
- ],
160
- 'factories ' => [
161
- 'foo-bar ' => TestAsset \Factory::class,
162
- ],
163
- 'delegators ' => [
164
- 'alias ' => [
165
- TestAsset \DelegatorFactory::class,
166
- ],
167
- ],
168
- ];
169
-
170
- $ container = $ this ->createContainer ($ config );
171
-
172
- self ::assertTrue ($ container ->has ('alias ' ));
173
- $ instance = $ container ->get ('alias ' );
174
- self ::assertInstanceOf (TestAsset \Service::class, $ instance );
175
- self ::assertNotInstanceOf (TestAsset \Delegator::class, $ instance );
176
-
177
- // Now ensure that the instance already retrieved by alias is the same
178
- // as that when fetched by the canonical service name.
179
- self ::assertSame ($ instance , $ container ->get ('foo-bar ' ));
180
- }
181
-
182
154
public function testDelegatorsDoNotTriggerForAliasTargetingInvokableService () : void
183
155
{
184
156
$ config = [
@@ -207,38 +179,6 @@ public function testDelegatorsDoNotTriggerForAliasTargetingInvokableService() :
207
179
self ::assertSame ($ instance , $ container ->get (TestAsset \Service::class));
208
180
}
209
181
210
- public function testDelegatorsTriggerForFactoryServiceResolvedByAlias () : void
211
- {
212
- $ config = [
213
- 'aliases ' => [
214
- 'alias ' => 'foo-bar ' ,
215
- ],
216
- 'factories ' => [
217
- 'foo-bar ' => TestAsset \Factory::class,
218
- ],
219
- 'delegators ' => [
220
- 'foo-bar ' => [
221
- TestAsset \DelegatorFactory::class,
222
- ],
223
- ],
224
- ];
225
-
226
- $ container = $ this ->createContainer ($ config );
227
-
228
- self ::assertTrue ($ container ->has ('alias ' ));
229
- $ instance = $ container ->get ('alias ' );
230
- self ::assertInstanceOf (TestAsset \Delegator::class, $ instance );
231
- self ::assertInstanceOf (TestAsset \Service::class, ($ instance ->callback )());
232
-
233
- // Now ensure that the instance already retrieved by alias is the same
234
- // as that when fetched by the canonical service name.
235
- self ::assertSame ($ instance , $ container ->get ('foo-bar ' ));
236
-
237
- // Now ensure that subsequent retrievals by alias retrieve the same
238
- // instance.
239
- self ::assertSame ($ instance , $ container ->get ('alias ' ));
240
- }
241
-
242
182
public function delegatorService () : Generator
243
183
{
244
184
yield 'invokable ' => [
@@ -257,14 +197,6 @@ public function delegatorService() : Generator
257
197
TestAsset \Service::class,
258
198
];
259
199
260
- yield 'factory-service ' => [
261
- [
262
- 'factories ' => ['foo-bar ' => TestAsset \Factory::class],
263
- ],
264
- 'foo-bar ' ,
265
- 'foo-bar ' ,
266
- ];
267
-
268
200
yield 'alias-of-invokable ' => [
269
201
[
270
202
'aliases ' => ['foo-bar ' => TestAsset \Service::class],
@@ -274,14 +206,19 @@ public function delegatorService() : Generator
274
206
TestAsset \Service::class,
275
207
];
276
208
277
- yield 'alias-of-factory-service ' => [
278
- [
279
- 'aliases ' => ['alias ' => 'foo-bar ' ],
280
- 'factories ' => ['foo-bar ' => TestAsset \Factory::class],
281
- ],
282
- 'alias ' ,
283
- 'foo-bar ' ,
284
- ];
209
+ foreach ($ this ->factoriesForDelegators () as $ name => $ params ) {
210
+ yield 'factory-service- ' . $ name => [
211
+ $ params [0 ],
212
+ 'service ' ,
213
+ 'service ' ,
214
+ ];
215
+
216
+ yield 'alias-of-factory-service- ' . $ name => [
217
+ $ params [0 ] + ['aliases ' => ['alias ' => 'service ' ]],
218
+ 'alias ' ,
219
+ 'service ' ,
220
+ ];
221
+ }
285
222
}
286
223
287
224
/**
@@ -456,6 +393,67 @@ public function testDelegatorFactoriesTriggerForFactoryBackedServicesUsingAnyFac
456
393
// Retrieving a second time should retrieve the same instance.
457
394
self ::assertSame ($ instance , $ container ->get ('service ' ));
458
395
}
396
+
397
+ /**
398
+ * @dataProvider factoriesForDelegators
399
+ */
400
+ public function testDelegatorsTriggerForFactoryServiceResolvedByAlias (array $ config ) : void
401
+ {
402
+ $ config += [
403
+ 'aliases ' => [
404
+ 'alias ' => 'service ' ,
405
+ ],
406
+ 'delegators ' => [
407
+ 'service ' => [
408
+ TestAsset \DelegatorFactory::class,
409
+ ],
410
+ ],
411
+ ];
412
+
413
+ $ container = $ this ->createContainer ($ config );
414
+
415
+ self ::assertTrue ($ container ->has ('alias ' ));
416
+ $ instance = $ container ->get ('alias ' );
417
+ self ::assertInstanceOf (TestAsset \Delegator::class, $ instance );
418
+ self ::assertInstanceOf (TestAsset \Service::class, ($ instance ->callback )());
419
+
420
+ // Now ensure that the instance already retrieved by alias is the same
421
+ // as that when fetched by the canonical service name.
422
+ self ::assertSame ($ instance , $ container ->get ('service ' ));
423
+
424
+ // Now ensure that subsequent retrievals by alias retrieve the same
425
+ // instance.
426
+ self ::assertSame ($ instance , $ container ->get ('alias ' ));
427
+ }
428
+
429
+ /**
430
+ * @dataProvider factoriesForDelegators
431
+ */
432
+ public function testDelegatorsDoNotTriggerForAliasTargetingFactoryBasedServiceUsingAnyFactoryType (
433
+ array $ config
434
+ ) : void {
435
+ $ config += [
436
+ 'aliases ' => [
437
+ 'alias ' => 'service ' ,
438
+ ],
439
+ 'delegators ' => [
440
+ 'alias ' => [
441
+ TestAsset \DelegatorFactory::class,
442
+ ],
443
+ ],
444
+ ];
445
+
446
+ $ container = $ this ->createContainer ($ config );
447
+
448
+ self ::assertTrue ($ container ->has ('alias ' ));
449
+ $ instance = $ container ->get ('alias ' );
450
+ self ::assertInstanceOf (TestAsset \Service::class, $ instance );
451
+ self ::assertNotInstanceOf (TestAsset \Delegator::class, $ instance );
452
+
453
+ // Now ensure that the instance already retrieved by alias is the same
454
+ // as that when fetched by the canonical service name.
455
+ self ::assertSame ($ instance , $ container ->get ('service ' ));
456
+ }
459
457
460
458
// @codingStandardsIgnoreStart
461
459
public function testWhenInvokableWithDelegatorsResolvesToNonExistentClassNoExceptionIsRaisedIfCallbackNeverInvoked ()
0 commit comments