|
17 | 17 | use Symfony\Component\DependencyInjection\Reference;
|
18 | 18 | use Symfony\Component\DependencyInjection\ServiceLocator;
|
19 | 19 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
| 20 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; |
| 21 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition2; |
20 | 22 |
|
21 | 23 | require_once __DIR__.'/../Fixtures/includes/classes.php';
|
22 | 24 |
|
@@ -76,8 +78,54 @@ public function testProcessValue()
|
76 | 78 | /** @var ServiceLocator $locator */
|
77 | 79 | $locator = $container->get('foo');
|
78 | 80 |
|
79 |
| - $this->assertEquals(CustomDefinition::class, \get_class($locator('bar'))); |
80 |
| - $this->assertEquals(CustomDefinition::class, \get_class($locator('baz'))); |
81 |
| - $this->assertEquals(CustomDefinition::class, \get_class($locator('some.service'))); |
| 81 | + $this->assertSame(CustomDefinition::class, \get_class($locator('bar'))); |
| 82 | + $this->assertSame(CustomDefinition::class, \get_class($locator('baz'))); |
| 83 | + $this->assertSame(CustomDefinition::class, \get_class($locator('some.service'))); |
| 84 | + } |
| 85 | + |
| 86 | + public function testServiceWithKeyOverwritesPreviousInheritedKey() |
| 87 | + { |
| 88 | + $container = new ContainerBuilder(); |
| 89 | + |
| 90 | + $container->register('bar', TestDefinition1::class); |
| 91 | + $container->register('baz', TestDefinition2::class); |
| 92 | + |
| 93 | + $container->register('foo', ServiceLocator::class) |
| 94 | + ->setArguments(array(array( |
| 95 | + new Reference('bar'), |
| 96 | + 'bar' => new Reference('baz'), |
| 97 | + ))) |
| 98 | + ->addTag('container.service_locator') |
| 99 | + ; |
| 100 | + |
| 101 | + (new ServiceLocatorTagPass())->process($container); |
| 102 | + |
| 103 | + /** @var ServiceLocator $locator */ |
| 104 | + $locator = $container->get('foo'); |
| 105 | + |
| 106 | + $this->assertSame(TestDefinition2::class, \get_class($locator('bar'))); |
| 107 | + } |
| 108 | + |
| 109 | + public function testInheritedKeyOverwritesPreviousServiceWithKey() |
| 110 | + { |
| 111 | + $container = new ContainerBuilder(); |
| 112 | + |
| 113 | + $container->register('bar', TestDefinition1::class); |
| 114 | + $container->register('baz', TestDefinition2::class); |
| 115 | + |
| 116 | + $container->register('foo', ServiceLocator::class) |
| 117 | + ->setArguments(array(array( |
| 118 | + 'bar' => new Reference('baz'), |
| 119 | + new Reference('bar'), |
| 120 | + ))) |
| 121 | + ->addTag('container.service_locator') |
| 122 | + ; |
| 123 | + |
| 124 | + (new ServiceLocatorTagPass())->process($container); |
| 125 | + |
| 126 | + /** @var ServiceLocator $locator */ |
| 127 | + $locator = $container->get('foo'); |
| 128 | + |
| 129 | + $this->assertSame(TestDefinition1::class, \get_class($locator('bar'))); |
82 | 130 | }
|
83 | 131 | }
|
0 commit comments