@@ -218,6 +218,9 @@ public function testTaggedItemAttributes()
218
218
$ container ->register ('service5 ' , HelloNamedService2::class)
219
219
->setAutoconfigured (true )
220
220
->addTag ('my_custom_tag ' );
221
+ $ container ->register ('service6 ' , MultiTagHelloNamedService::class)
222
+ ->setAutoconfigured (true )
223
+ ->addTag ('my_custom_tag ' );
221
224
222
225
(new ResolveInstanceofConditionalsPass ())->process ($ container );
223
226
@@ -226,14 +229,33 @@ public function testTaggedItemAttributes()
226
229
$ tag = new TaggedIteratorArgument ('my_custom_tag ' , 'foo ' , 'getFooBar ' , exclude: ['service4 ' , 'service5 ' ]);
227
230
$ expected = [
228
231
'service3 ' => new TypedReference ('service3 ' , HelloNamedService2::class),
232
+ 'multi_hello_2 ' => new TypedReference ('service6 ' , MultiTagHelloNamedService::class),
229
233
'hello ' => new TypedReference ('service2 ' , HelloNamedService::class),
234
+ 'multi_hello_1 ' => new TypedReference ('service6 ' , MultiTagHelloNamedService::class),
230
235
'service1 ' => new TypedReference ('service1 ' , FooTagClass::class),
231
236
];
237
+
232
238
$ services = $ priorityTaggedServiceTraitImplementation ->test ($ tag , $ container );
233
239
$ this ->assertSame (array_keys ($ expected ), array_keys ($ services ));
234
240
$ this ->assertEquals ($ expected , $ priorityTaggedServiceTraitImplementation ->test ($ tag , $ container ));
235
241
}
236
242
243
+ public function testTaggedItemAttributesRepeatedWithoutNameThrows ()
244
+ {
245
+ $ container = new ContainerBuilder ();
246
+ $ container ->register ('service1 ' , MultiNoNameTagHelloNamedService::class)
247
+ ->setAutoconfigured (true )
248
+ ->addTag ('my_custom_tag ' );
249
+
250
+ (new ResolveInstanceofConditionalsPass ())->process ($ container );
251
+ $ tag = new TaggedIteratorArgument ('my_custom_tag ' , 'foo ' , 'getFooBar ' , exclude: ['service4 ' , 'service5 ' ]);
252
+
253
+ $ this ->expectException (InvalidArgumentException::class);
254
+ $ this ->expectExceptionMessage ('Attribute "Symfony\Component\DependencyInjection\Attribute\AsTaggedItem" on class "Symfony\Component\DependencyInjection\Tests\Compiler\MultiNoNameTagHelloNamedService" cannot have an empty index when repeated. ' );
255
+
256
+ (new PriorityTaggedServiceTraitImplementation ())->test ($ tag , $ container );
257
+ }
258
+
237
259
public function testResolveIndexedTags ()
238
260
{
239
261
$ container = new ContainerBuilder ();
@@ -283,6 +305,18 @@ class HelloNamedService2
283
305
{
284
306
}
285
307
308
+ #[AsTaggedItem(index: 'multi_hello_1 ' , priority: 1 )]
309
+ #[AsTaggedItem(index: 'multi_hello_2 ' , priority: 2 )]
310
+ class MultiTagHelloNamedService
311
+ {
312
+ }
313
+
314
+ #[AsTaggedItem(priority: 1 )]
315
+ #[AsTaggedItem(priority: 2 )]
316
+ class MultiNoNameTagHelloNamedService
317
+ {
318
+ }
319
+
286
320
interface HelloInterface
287
321
{
288
322
public static function getFooBar (): string ;
0 commit comments