@@ -218,6 +218,9 @@ public function testTaggedItemAttributes()
218218 $ container ->register ('service5 ' , HelloNamedService2::class)
219219 ->setAutoconfigured (true )
220220 ->addTag ('my_custom_tag ' );
221+ $ container ->register ('service6 ' , MultiTagHelloNamedService::class)
222+ ->setAutoconfigured (true )
223+ ->addTag ('my_custom_tag ' );
221224
222225 (new ResolveInstanceofConditionalsPass ())->process ($ container );
223226
@@ -226,14 +229,33 @@ public function testTaggedItemAttributes()
226229 $ tag = new TaggedIteratorArgument ('my_custom_tag ' , 'foo ' , 'getFooBar ' , exclude: ['service4 ' , 'service5 ' ]);
227230 $ expected = [
228231 'service3 ' => new TypedReference ('service3 ' , HelloNamedService2::class),
232+ 'multi_hello_2 ' => new TypedReference ('service6 ' , MultiTagHelloNamedService::class),
229233 'hello ' => new TypedReference ('service2 ' , HelloNamedService::class),
234+ 'multi_hello_1 ' => new TypedReference ('service6 ' , MultiTagHelloNamedService::class),
230235 'service1 ' => new TypedReference ('service1 ' , FooTagClass::class),
231236 ];
237+
232238 $ services = $ priorityTaggedServiceTraitImplementation ->test ($ tag , $ container );
233239 $ this ->assertSame (array_keys ($ expected ), array_keys ($ services ));
234240 $ this ->assertEquals ($ expected , $ priorityTaggedServiceTraitImplementation ->test ($ tag , $ container ));
235241 }
236242
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+
237259 public function testResolveIndexedTags ()
238260 {
239261 $ container = new ContainerBuilder ();
@@ -283,6 +305,18 @@ class HelloNamedService2
283305{
284306}
285307
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+
286320interface HelloInterface
287321{
288322 public static function getFooBar (): string ;
0 commit comments