@@ -78,6 +78,41 @@ public function testDoesNothingWhenChainLoaderIsAbsent(): void
7878 $ this ->assertFalse ($ container ->hasDefinition ('serializer.mapping.chain_loader ' ));
7979 }
8080
81+ public function testDoesNothingWhenChainAlreadyContainsAnAttributeLoader (): void
82+ {
83+ $ container = new ContainerBuilder ();
84+ $ existing = new Definition (AttributeLoader::class);
85+ $ container ->setDefinition ('serializer.mapping.chain_loader ' , new Definition (LoaderChain::class, [[$ existing ]]));
86+ $ container ->setDefinition ('serializer.mapping.cache_warmer ' , new Definition (\stdClass::class, [[$ existing ]]));
87+
88+ (new ErrorResourceAttributeLoaderPass ())->process ($ container );
89+
90+ $ loaders = $ container ->getDefinition ('serializer.mapping.chain_loader ' )->getArgument (0 );
91+ $ this ->assertCount (1 , $ loaders , 'pass must not add another AttributeLoader when one is already wired (enable_attributes: true). ' );
92+
93+ $ warmerLoaders = $ container ->getDefinition ('serializer.mapping.cache_warmer ' )->getArgument (0 );
94+ $ this ->assertCount (1 , $ warmerLoaders );
95+ }
96+
97+ /**
98+ * @see https://github.com/api-platform/core/issues/8244
99+ */
100+ public function testSkipsOnSymfony64SerializerSignature (): void
101+ {
102+ if (!class_exists (\Symfony \Component \Serializer \Mapping \Loader \AnnotationLoader::class)) {
103+ $ this ->markTestSkipped ('Only relevant when running against symfony/serializer 6.4 (AnnotationLoader still present). ' );
104+ }
105+
106+ $ container = new ContainerBuilder ();
107+ $ container ->setDefinition ('serializer.mapping.chain_loader ' , new Definition (LoaderChain::class, [[]]));
108+ $ container ->setDefinition ('serializer.mapping.cache_warmer ' , new Definition (\stdClass::class, [[]]));
109+
110+ (new ErrorResourceAttributeLoaderPass ())->process ($ container );
111+
112+ $ this ->assertSame ([], $ container ->getDefinition ('serializer.mapping.chain_loader ' )->getArgument (0 ));
113+ $ this ->assertSame ([], $ container ->getDefinition ('serializer.mapping.cache_warmer ' )->getArgument (0 ));
114+ }
115+
81116 /**
82117 * Mirrors the runtime behavior with `framework.serializer.enable_attributes: false`:
83118 * Symfony builds the `AttributeLoader` with `allowAnyClass = false` and no mapped classes,
0 commit comments