21
21
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
22
22
use Symfony \Component \DependencyInjection \Reference ;
23
23
use Symfony \Component \DependencyInjection \ServiceLocator ;
24
- use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
25
24
use Symfony \Component \DependencyInjection \Tests \Fixtures \TestDefinition1 ;
26
25
use Symfony \Component \DependencyInjection \Tests \Fixtures \TestDefinition2 ;
27
26
@@ -62,8 +61,8 @@ public function testProcessValue()
62
61
{
63
62
$ container = new ContainerBuilder ();
64
63
65
- $ container ->register ('bar ' , CustomDefinition ::class);
66
- $ container ->register ('baz ' , CustomDefinition ::class);
64
+ $ container ->register ('bar ' , TestDefinition1 ::class);
65
+ $ container ->register ('baz ' , TestDefinition2 ::class);
67
66
68
67
$ container ->register ('foo ' , ServiceLocator::class)
69
68
->setArguments ([[
@@ -79,9 +78,33 @@ public function testProcessValue()
79
78
/** @var ServiceLocator $locator */
80
79
$ locator = $ container ->get ('foo ' );
81
80
82
- $ this ->assertSame (CustomDefinition::class, $ locator ('bar ' )::class);
83
- $ this ->assertSame (CustomDefinition::class, $ locator ('baz ' )::class);
84
- $ this ->assertSame (CustomDefinition::class, $ locator ('some.service ' )::class);
81
+ $ this ->assertInstanceOf (TestDefinition1::class, $ locator ('bar ' ));
82
+ $ this ->assertInstanceOf (TestDefinition2::class, $ locator ('baz ' ));
83
+ $ this ->assertInstanceOf (TestDefinition1::class, $ locator ('some.service ' ));
84
+ }
85
+
86
+ public function testProcessLocatorArgumentValue ()
87
+ {
88
+ $ container = new ContainerBuilder ();
89
+
90
+ $ container ->register ('bar ' , TestDefinition1::class);
91
+ $ container ->register ('baz ' , TestDefinition2::class);
92
+
93
+ $ container ->register ('foo ' , Locator::class)
94
+ ->addArgument (new ServiceLocatorArgument ([
95
+ new Reference ('bar ' ),
96
+ 'some.service ' => new Reference ('bar ' ),
97
+ new Reference ('baz ' ),
98
+ ]));
99
+
100
+ (new ServiceLocatorTagPass ())->process ($ container );
101
+
102
+ /** @var ServiceLocator $locator */
103
+ $ locator = $ container ->get ('foo ' )->locator ;
104
+
105
+ $ this ->assertInstanceOf (TestDefinition1::class, $ locator ('bar ' ));
106
+ $ this ->assertInstanceOf (TestDefinition1::class, $ locator ('some.service ' ));
107
+ $ this ->assertInstanceOf (TestDefinition2::class, $ locator ('baz ' ));
85
108
}
86
109
87
110
public function testServiceWithKeyOverwritesPreviousInheritedKey ()
@@ -104,7 +127,7 @@ public function testServiceWithKeyOverwritesPreviousInheritedKey()
104
127
/** @var ServiceLocator $locator */
105
128
$ locator = $ container ->get ('foo ' );
106
129
107
- $ this ->assertSame (TestDefinition2::class, $ locator ('bar ' )::class );
130
+ $ this ->assertInstanceOf (TestDefinition2::class, $ locator ('bar ' ));
108
131
}
109
132
110
133
public function testInheritedKeyOverwritesPreviousServiceWithKey ()
@@ -128,8 +151,8 @@ public function testInheritedKeyOverwritesPreviousServiceWithKey()
128
151
/** @var ServiceLocator $locator */
129
152
$ locator = $ container ->get ('foo ' );
130
153
131
- $ this ->assertSame (TestDefinition1::class, $ locator ('bar ' )::class );
132
- $ this ->assertSame (TestDefinition2::class, $ locator (16 )::class );
154
+ $ this ->assertInstanceOf (TestDefinition1::class, $ locator ('bar ' ));
155
+ $ this ->assertInstanceOf (TestDefinition2::class, $ locator (16 ));
133
156
}
134
157
135
158
public function testBindingsAreCopied ()
@@ -164,8 +187,8 @@ public function testTaggedServices()
164
187
/** @var ServiceLocator $locator */
165
188
$ locator = $ container ->get ('foo ' );
166
189
167
- $ this ->assertSame (TestDefinition1::class, $ locator ('bar ' )::class );
168
- $ this ->assertSame (TestDefinition2::class, $ locator ('baz ' )::class );
190
+ $ this ->assertInstanceOf (TestDefinition1::class, $ locator ('bar ' ));
191
+ $ this ->assertInstanceOf (TestDefinition2::class, $ locator ('baz ' ));
169
192
}
170
193
171
194
public function testIndexedByServiceIdWithDecoration ()
@@ -184,19 +207,19 @@ public function testIndexedByServiceIdWithDecoration()
184
207
185
208
$ container ->setDefinition (Service::class, $ service );
186
209
187
- $ decorated = new Definition (Decorated ::class);
210
+ $ decorated = new Definition (DecoratedService ::class);
188
211
$ decorated ->setPublic (true );
189
212
$ decorated ->setDecoratedService (Service::class);
190
213
191
- $ container ->setDefinition (Decorated ::class, $ decorated );
214
+ $ container ->setDefinition (DecoratedService ::class, $ decorated );
192
215
193
216
$ container ->compile ();
194
217
195
218
/** @var ServiceLocator $locator */
196
219
$ locator = $ container ->get (Locator::class)->locator ;
197
220
static ::assertTrue ($ locator ->has (Service::class));
198
- static ::assertFalse ($ locator ->has (Decorated ::class));
199
- static ::assertInstanceOf (Decorated ::class, $ locator ->get (Service::class));
221
+ static ::assertFalse ($ locator ->has (DecoratedService ::class));
222
+ static ::assertInstanceOf (DecoratedService ::class, $ locator ->get (Service::class));
200
223
}
201
224
202
225
public function testDefinitionOrderIsTheSame ()
0 commit comments