@@ -257,11 +257,7 @@ public function testCanCreateNewLocatorWithMergedConfig()
257
257
$ this ->assertTrue ($ newServiceManager ->has (stdClass::class));
258
258
259
259
// Make sure the context has been updated for the new container
260
-
261
- $ reflectionProperty = new \ReflectionProperty ($ newServiceManager , 'creationContext ' );
262
- $ reflectionProperty ->setAccessible (true );
263
-
264
- $ this ->assertSame ($ newServiceManager , $ reflectionProperty ->getValue ($ newServiceManager ));
260
+ $ this ->assertAttributeSame ($ newServiceManager , 'creationContext ' , $ newServiceManager );
265
261
}
266
262
267
263
public function testOverrideConfigWhenMerged ()
@@ -346,24 +342,24 @@ public function testHasDoesNotCheckAbstractFactoriesByDefault()
346
342
public function abstractFactories ()
347
343
{
348
344
return [
349
- 'simple ' => [new SimpleAbstractFactory (), ' assertTrue ' ],
350
- 'failing ' => [new FailingAbstractFactory (), ' assertFalse ' ],
345
+ 'simple ' => [new SimpleAbstractFactory (), true ],
346
+ 'failing ' => [new FailingAbstractFactory (), false ],
351
347
];
352
348
}
353
349
354
350
/**
355
351
* @group has
356
352
* @dataProvider abstractFactories
357
353
*/
358
- public function testHasCanCheckAbstractFactoriesWhenRequested ($ abstractFactory , $ assertion )
354
+ public function testHasCanCheckAbstractFactoriesWhenRequested ($ abstractFactory , $ expected )
359
355
{
360
356
$ serviceManager = $ this ->createContainer ([
361
357
'abstract_factories ' => [
362
358
$ abstractFactory ,
363
359
],
364
360
]);
365
361
366
- $ this ->{ $ assertion }( $ serviceManager ->has (DateTime::class, true ));
362
+ $ this ->assertSame ( $ expected , $ serviceManager ->has (DateTime::class, true ));
367
363
}
368
364
369
365
/**
@@ -409,20 +405,40 @@ function ($container, $instance) {
409
405
]);
410
406
411
407
$ dateTime = $ serviceManager ->get (DateTime::class);
412
- $ this ->assertInstanceOf (DateTime::class, $ dateTime );
408
+ $ this ->assertInstanceOf (DateTime::class, $ dateTime, ' DateTime service did not resolve as expected ' );
413
409
$ notShared = $ serviceManager ->get (DateTime::class);
414
- $ this ->assertInstanceOf (DateTime::class, $ notShared );
415
- $ this ->assertNotSame ($ dateTime , $ notShared );
410
+ $ this ->assertInstanceOf (DateTime::class, $ notShared , 'DateTime service did not re-resolve as expected ' );
411
+ $ this ->assertNotSame (
412
+ $ dateTime ,
413
+ $ notShared ,
414
+ 'Expected unshared instances for DateTime service but received shared instances '
415
+ );
416
416
417
417
$ config = $ serviceManager ->get ('config ' );
418
- $ this ->assertInternalType ('array ' , $ config );
419
- $ this ->assertSame ($ config , $ serviceManager ->get ('config ' ));
418
+ $ this ->assertInternalType ('array ' , $ config , 'Config service did not resolve as expected ' );
419
+ $ this ->assertSame (
420
+ $ config ,
421
+ $ serviceManager ->get ('config ' ),
422
+ 'Config service resolved as unshared instead of shared '
423
+ );
420
424
421
425
$ stdClass = $ serviceManager ->get (stdClass::class);
422
- $ this ->assertInstanceOf (stdClass::class, $ stdClass );
423
- $ this ->assertSame ($ stdClass , $ serviceManager ->get (stdClass::class));
424
- $ this ->assertEquals ('bar ' , $ stdClass ->foo );
425
- $ this ->assertEquals ('baz ' , $ stdClass ->bar );
426
+ $ this ->assertInstanceOf (stdClass::class, $ stdClass , 'stdClass service did not resolve as expected ' );
427
+ $ this ->assertSame (
428
+ $ stdClass ,
429
+ $ serviceManager ->get (stdClass::class),
430
+ 'stdClass service should be shared, but resolved as unshared '
431
+ );
432
+ $ this ->assertTrue (
433
+ isset ($ stdClass ->foo ),
434
+ 'Expected delegator to inject "foo" property in stdClass service, but it was not '
435
+ );
436
+ $ this ->assertEquals ('bar ' , $ stdClass ->foo , 'stdClass "foo" property was not injected correctly ' );
437
+ $ this ->assertTrue (
438
+ isset ($ stdClass ->bar ),
439
+ 'Expected initializer to inject "bar" property in stdClass service, but it was not '
440
+ );
441
+ $ this ->assertEquals ('baz ' , $ stdClass ->bar , 'stdClass "bar" property was not injected correctly ' );
426
442
}
427
443
428
444
/**
@@ -482,7 +498,8 @@ public function testCanSpecifyInitializerUsingStringViaConfiguration()
482
498
483
499
$ instance = $ serviceManager ->get (stdClass::class);
484
500
$ this ->assertInstanceOf (stdClass::class, $ instance );
485
- $ this ->assertEquals ('bar ' , $ instance ->foo );
501
+ $ this ->assertTrue (isset ($ instance ->foo ), '"foo" property was not injected by initializer ' );
502
+ $ this ->assertEquals ('bar ' , $ instance ->foo , '"foo" property was not properly injected ' );
486
503
}
487
504
488
505
/**
0 commit comments