@@ -42,7 +42,7 @@ public function testLoadEmptyConfiguration()
4242 $ container ->loadFromExtension ('twig ' );
4343 $ this ->compileContainer ($ container );
4444
45- $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
45+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
4646
4747 $ this ->assertContains ('form_div_layout.html.twig ' , $ container ->getParameter ('twig.form.resources ' ), '->load() includes default template for form resources ' );
4848
@@ -73,7 +73,7 @@ public function testLoadFullConfiguration(string $format, ?string $buildDir)
7373 $ this ->loadFromFile ($ container , 'full ' , $ format );
7474 $ this ->compileContainer ($ container );
7575
76- $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
76+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
7777
7878 // Form resources
7979 $ resources = $ container ->getParameter ('twig.form.resources ' );
@@ -90,12 +90,51 @@ public function testLoadFullConfiguration(string $format, ?string $buildDir)
9090 $ this ->assertEquals ('@qux ' , $ calls [3 ][1 ][1 ], '->load() allows escaping of service identifiers ' );
9191 $ this ->assertEquals ('pi ' , $ calls [4 ][1 ][0 ], '->load() registers variables as Twig globals ' );
9292 $ this ->assertEquals (3.14 , $ calls [4 ][1 ][1 ], '->load() registers variables as Twig globals ' );
93+ $ this ->assertEquals ('bad ' , $ calls [5 ][1 ][0 ], '->load() registers variables as Twig globals ' );
94+ $ this ->assertEquals (['key ' => 'foo ' ], $ calls [5 ][1 ][1 ], '->load() registers variables as Twig globals ' );
9395
94- // Yaml and Php specific configs
95- if (\in_array ($ format , ['yml ' , 'php ' ])) {
96- $ this ->assertEquals ('bad ' , $ calls [5 ][1 ][0 ], '->load() registers variables as Twig globals ' );
97- $ this ->assertEquals (['key ' => 'foo ' ], $ calls [5 ][1 ][1 ], '->load() registers variables as Twig globals ' );
98- }
96+ // Twig options
97+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
98+ $ this ->assertFalse ($ options ['auto_reload ' ], '->load() sets the auto_reload option ' );
99+ $ this ->assertSame ('name ' , $ options ['autoescape ' ], '->load() sets the autoescape option ' );
100+ $ this ->assertArrayNotHasKey ('base_template_class ' , $ options , '->load() does not set the base_template_class if none is provided ' );
101+ $ this ->assertEquals ('ISO-8859-1 ' , $ options ['charset ' ], '->load() sets the charset option ' );
102+ $ this ->assertTrue ($ options ['debug ' ], '->load() sets the debug option ' );
103+ $ this ->assertTrue ($ options ['strict_variables ' ], '->load() sets the strict_variables option ' );
104+ $ this ->assertEquals ($ buildDir !== null ? new Reference ('twig.template_cache.chain ' ) : '%kernel.cache_dir%/twig ' , $ options ['cache ' ], '->load() sets the cache option ' );
105+ }
106+
107+ /**
108+ * @group legacy
109+ *
110+ * @dataProvider getXmlBuildDir
111+ */
112+ public function testLoadFullXmlConfiguration (?string $ buildDir )
113+ {
114+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
115+
116+ $ container = $ this ->createContainer ($ buildDir );
117+ $ container ->registerExtension (new TwigExtension ());
118+ $ this ->loadFromFile ($ container , 'full ' , 'xml ' );
119+ $ this ->compileContainer ($ container );
120+
121+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
122+
123+ // Form resources
124+ $ resources = $ container ->getParameter ('twig.form.resources ' );
125+ $ this ->assertContains ('form_div_layout.html.twig ' , $ resources , '->load() includes default template for form resources ' );
126+ $ this ->assertContains ('MyBundle::form.html.twig ' , $ resources , '->load() merges new templates into form resources ' );
127+
128+ // Globals
129+ $ calls = $ container ->getDefinition ('twig ' )->getMethodCalls ();
130+ $ this ->assertEquals ('app ' , $ calls [0 ][1 ][0 ], '->load() registers services as Twig globals ' );
131+ $ this ->assertEquals (new Reference ('twig.app_variable ' ), $ calls [0 ][1 ][1 ]);
132+ $ this ->assertEquals ('foo ' , $ calls [2 ][1 ][0 ], '->load() registers services as Twig globals ' );
133+ $ this ->assertEquals (new Reference ('bar ' ), $ calls [2 ][1 ][1 ], '->load() registers services as Twig globals ' );
134+ $ this ->assertEquals ('baz ' , $ calls [3 ][1 ][0 ], '->load() registers variables as Twig globals ' );
135+ $ this ->assertEquals ('@qux ' , $ calls [3 ][1 ][1 ], '->load() allows escaping of service identifiers ' );
136+ $ this ->assertEquals ('pi ' , $ calls [4 ][1 ][0 ], '->load() registers variables as Twig globals ' );
137+ $ this ->assertEquals (3.14 , $ calls [4 ][1 ][1 ], '->load() registers variables as Twig globals ' );
99138
100139 // Twig options
101140 $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -118,7 +157,28 @@ public function testLoadNoCacheConfiguration(string $format, ?string $buildDir)
118157 $ this ->loadFromFile ($ container , 'no-cache ' , $ format );
119158 $ this ->compileContainer ($ container );
120159
121- $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
160+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
161+
162+ // Twig options
163+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
164+ $ this ->assertFalse ($ options ['cache ' ], '->load() sets cache option to false ' );
165+ }
166+
167+ /**
168+ * @group legacy
169+ *
170+ * @dataProvider getXmlBuildDir
171+ */
172+ public function testLoadNoCacheXmlConfiguration (?string $ buildDir )
173+ {
174+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
175+
176+ $ container = $ this ->createContainer ($ buildDir );
177+ $ container ->registerExtension (new TwigExtension ());
178+ $ this ->loadFromFile ($ container , 'no-cache ' , 'xml ' );
179+ $ this ->compileContainer ($ container );
180+
181+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
122182
123183 // Twig options
124184 $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -135,7 +195,28 @@ public function testLoadPathCacheConfiguration(string $format, ?string $buildDir
135195 $ this ->loadFromFile ($ container , 'path-cache ' , $ format );
136196 $ this ->compileContainer ($ container );
137197
138- $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
198+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
199+
200+ // Twig options
201+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
202+ $ this ->assertSame ('random-path ' , $ options ['cache ' ], '->load() sets cache option to string path ' );
203+ }
204+
205+ /**
206+ * @group legacy
207+ *
208+ * @dataProvider getXmlBuildDir
209+ */
210+ public function testLoadPathCacheXmlConfiguration (?string $ buildDir )
211+ {
212+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
213+
214+ $ container = $ this ->createContainer ($ buildDir );
215+ $ container ->registerExtension (new TwigExtension ());
216+ $ this ->loadFromFile ($ container , 'path-cache ' , 'xml ' );
217+ $ this ->compileContainer ($ container );
218+
219+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
139220
140221 // Twig options
141222 $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -152,7 +233,28 @@ public function testLoadProdCacheConfiguration(string $format, ?string $buildDir
152233 $ this ->loadFromFile ($ container , 'prod-cache ' , $ format );
153234 $ this ->compileContainer ($ container );
154235
155- $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
236+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
237+
238+ // Twig options
239+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
240+ $ this ->assertEquals ($ buildDir !== null ? new Reference ('twig.template_cache.chain ' ) : '%kernel.cache_dir%/twig ' , $ options ['cache ' ], '->load() sets cache option to CacheChain reference ' );
241+ }
242+
243+ /**
244+ * @group legacy
245+ *
246+ * @dataProvider getXmlBuildDir
247+ */
248+ public function testLoadProdCacheXmlConfiguration (?string $ buildDir )
249+ {
250+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
251+
252+ $ container = $ this ->createContainer ($ buildDir );
253+ $ container ->registerExtension (new TwigExtension ());
254+ $ this ->loadFromFile ($ container , 'prod-cache ' , 'xml ' );
255+ $ this ->compileContainer ($ container );
256+
257+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.php file ' );
156258
157259 // Twig options
158260 $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -192,6 +294,22 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration(string $forma
192294 $ this ->assertEquals ([new Reference ('my_project.some_bundle.template_escaping_guesser ' ), 'guess ' ], $ options ['autoescape ' ]);
193295 }
194296
297+ /**
298+ * @group legacy
299+ */
300+ public function testLoadCustomTemplateEscapingGuesserXmlConfiguration ()
301+ {
302+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
303+
304+ $ container = $ this ->createContainer ();
305+ $ container ->registerExtension (new TwigExtension ());
306+ $ this ->loadFromFile ($ container , 'customTemplateEscapingGuesser ' , 'xml ' );
307+ $ this ->compileContainer ($ container );
308+
309+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
310+ $ this ->assertEquals ([new Reference ('my_project.some_bundle.template_escaping_guesser ' ), 'guess ' ], $ options ['autoescape ' ]);
311+ }
312+
195313 /**
196314 * @dataProvider getFormats
197315 */
@@ -206,6 +324,22 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration(string $form
206324 $ this ->assertEquals ('name ' , $ options ['autoescape ' ]);
207325 }
208326
327+ /**
328+ * @group legacy
329+ */
330+ public function testLoadDefaultTemplateEscapingGuesserXmlConfiguration ()
331+ {
332+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
333+
334+ $ container = $ this ->createContainer ();
335+ $ container ->registerExtension (new TwigExtension ());
336+ $ this ->loadFromFile ($ container , 'empty ' , 'xml ' );
337+ $ this ->compileContainer ($ container );
338+
339+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
340+ $ this ->assertEquals ('name ' , $ options ['autoescape ' ]);
341+ }
342+
209343 /**
210344 * @dataProvider getFormats
211345 */
@@ -226,6 +360,28 @@ public function testLoadCustomDateFormats(string $fileFormat)
226360 $ this ->assertSame ('. ' , $ environmentConfigurator ->getArgument (5 ));
227361 }
228362
363+ /**
364+ * @group legacy
365+ */
366+ public function testLoadXmlCustomDateFormats ()
367+ {
368+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
369+
370+ $ container = $ this ->createContainer ();
371+ $ container ->registerExtension (new TwigExtension ());
372+ $ this ->loadFromFile ($ container , 'formats ' , 'xml ' );
373+ $ this ->compileContainer ($ container );
374+
375+ $ environmentConfigurator = $ container ->getDefinition ('twig.configurator.environment ' );
376+
377+ $ this ->assertSame ('Y-m-d ' , $ environmentConfigurator ->getArgument (0 ));
378+ $ this ->assertSame ('%d ' , $ environmentConfigurator ->getArgument (1 ));
379+ $ this ->assertSame ('Europe/Berlin ' , $ environmentConfigurator ->getArgument (2 ));
380+ $ this ->assertSame (2 , $ environmentConfigurator ->getArgument (3 ));
381+ $ this ->assertSame (', ' , $ environmentConfigurator ->getArgument (4 ));
382+ $ this ->assertSame ('. ' , $ environmentConfigurator ->getArgument (5 ));
383+ }
384+
229385 public function testGlobalsWithDifferentTypesAndValues ()
230386 {
231387 $ globals = [
@@ -287,12 +443,45 @@ public function testTwigLoaderPaths(string $format)
287443 ], $ paths );
288444 }
289445
446+ /**
447+ * @group legacy
448+ */
449+ public function testTwigXmlLoaderPaths ()
450+ {
451+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
452+
453+ $ container = $ this ->createContainer ();
454+ $ container ->registerExtension (new TwigExtension ());
455+ $ this ->loadFromFile ($ container , 'full ' , 'xml ' );
456+ $ this ->loadFromFile ($ container , 'extra ' , 'xml ' );
457+ $ this ->compileContainer ($ container );
458+
459+ $ def = $ container ->getDefinition ('twig.loader.native_filesystem ' );
460+ $ paths = [];
461+ foreach ($ def ->getMethodCalls () as $ call ) {
462+ if ('addPath ' === $ call [0 ] && !str_contains ($ call [1 ][0 ], 'Form ' )) {
463+ $ paths [] = $ call [1 ];
464+ }
465+ }
466+
467+ $ this ->assertEquals ([
468+ ['path1 ' ],
469+ ['path2 ' ],
470+ ['namespaced_path1 ' , 'namespace1 ' ],
471+ ['namespaced_path2 ' , 'namespace2 ' ],
472+ ['namespaced_path3 ' , 'namespace3 ' ],
473+ [__DIR__ .'/Fixtures/templates/bundles/AcmeBundle ' , 'Acme ' ],
474+ [__DIR__ .'/AcmeBundle/Resources/views ' , 'Acme ' ],
475+ [__DIR__ .'/AcmeBundle/Resources/views ' , '!Acme ' ],
476+ [__DIR__ .'/Fixtures/templates ' ],
477+ ], $ paths );
478+ }
479+
290480 public static function getFormats (): array
291481 {
292482 return [
293483 ['php ' ],
294484 ['yml ' ],
295- ['xml ' ],
296485 ];
297486 }
298487
@@ -303,8 +492,14 @@ public static function getFormatsAndBuildDir(): array
303492 ['php ' , __DIR__ .'/build ' ],
304493 ['yml ' , null ],
305494 ['yml ' , __DIR__ .'/build ' ],
306- ['xml ' , null ],
307- ['xml ' , __DIR__ .'/build ' ],
495+ ];
496+ }
497+
498+ public static function getXmlBuildDir (): array
499+ {
500+ return [
501+ [null ],
502+ [__DIR__ .'/build ' ],
308503 ];
309504 }
310505
@@ -383,6 +578,27 @@ public function testCustomHtmlToTextConverterService(string $format)
383578 $ this ->assertEquals (new Reference ('my_converter ' ), $ bodyRenderer ->getArgument ('$converter ' ));
384579 }
385580
581+ /**
582+ * @group legacy
583+ */
584+ public function testXmlCustomHtmlToTextConverterService ()
585+ {
586+ if (!class_exists (Mailer::class)) {
587+ $ this ->markTestSkipped ('The "twig.mime_body_renderer" service requires the Mailer component ' );
588+ }
589+
590+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
591+
592+ $ container = $ this ->createContainer ();
593+ $ container ->registerExtension (new TwigExtension ());
594+ $ this ->loadFromFile ($ container , 'mailer ' , 'xml ' );
595+ $ this ->compileContainer ($ container );
596+
597+ $ bodyRenderer = $ container ->getDefinition ('twig.mime_body_renderer ' );
598+ $ this ->assertCount (3 , $ bodyRenderer ->getArguments ());
599+ $ this ->assertEquals (new Reference ('my_converter ' ), $ bodyRenderer ->getArgument ('$converter ' ));
600+ }
601+
386602 private function createContainer (?string $ buildDir = null ): ContainerBuilder
387603 {
388604 $ container = new ContainerBuilder (new ParameterBag ([
0 commit comments