11
11
12
12
namespace Symfony \Bundle \TwigBundle \Tests \DependencyInjection ;
13
13
14
+ use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
14
15
use Symfony \Bundle \TwigBundle \DependencyInjection \Compiler \RuntimeLoaderPass ;
15
16
use Symfony \Bundle \TwigBundle \DependencyInjection \TwigExtension ;
16
17
use Symfony \Bundle \TwigBundle \Tests \DependencyInjection \AcmeBundle \AcmeBundle ;
31
32
32
33
class TwigExtensionTest extends TestCase
33
34
{
35
+ use ExpectDeprecationTrait;
36
+
34
37
public function testLoadEmptyConfiguration ()
35
38
{
36
39
$ container = $ this ->createContainer ();
@@ -56,7 +59,7 @@ public function testLoadEmptyConfiguration()
56
59
/**
57
60
* @dataProvider getFormats
58
61
*/
59
- public function testLoadFullConfiguration ($ format )
62
+ public function testLoadFullConfiguration (string $ format )
60
63
{
61
64
$ container = $ this ->createContainer ();
62
65
$ container ->registerExtension (new TwigExtension ());
@@ -91,17 +94,36 @@ public function testLoadFullConfiguration($format)
91
94
$ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
92
95
$ this ->assertTrue ($ options ['auto_reload ' ], '->load() sets the auto_reload option ' );
93
96
$ this ->assertSame ('name ' , $ options ['autoescape ' ], '->load() sets the autoescape option ' );
94
- $ this ->assertEquals ( ' stdClass ' , $ options[ ' base_template_class ' ] , '->load() sets the base_template_class option ' );
97
+ $ this ->assertArrayNotHasKey ( ' base_template_class ' , $ options , '->load() does not set the base_template_class if none is provided ' );
95
98
$ this ->assertEquals ('/tmp ' , $ options ['cache ' ], '->load() sets the cache option ' );
96
99
$ this ->assertEquals ('ISO-8859-1 ' , $ options ['charset ' ], '->load() sets the charset option ' );
97
100
$ this ->assertTrue ($ options ['debug ' ], '->load() sets the debug option ' );
98
101
$ this ->assertTrue ($ options ['strict_variables ' ], '->load() sets the strict_variables option ' );
99
102
}
100
103
104
+ /**
105
+ * @group legacy
106
+ *
107
+ * @dataProvider getFormats
108
+ */
109
+ public function testLoadCustomBaseTemplateClassConfiguration (string $ format )
110
+ {
111
+ $ container = $ this ->createContainer ();
112
+ $ container ->registerExtension (new TwigExtension ());
113
+
114
+ $ this ->expectDeprecation ('Since symfony/twig-bundle 7.1: The child node "base_template_class" at path "twig" is deprecated. ' );
115
+
116
+ $ this ->loadFromFile ($ container , 'templateClass ' , $ format );
117
+ $ this ->compileContainer ($ container );
118
+
119
+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
120
+ $ this ->assertEquals ('stdClass ' , $ options ['base_template_class ' ], '->load() sets the base_template_class option ' );
121
+ }
122
+
101
123
/**
102
124
* @dataProvider getFormats
103
125
*/
104
- public function testLoadCustomTemplateEscapingGuesserConfiguration ($ format )
126
+ public function testLoadCustomTemplateEscapingGuesserConfiguration (string $ format )
105
127
{
106
128
$ container = $ this ->createContainer ();
107
129
$ container ->registerExtension (new TwigExtension ());
@@ -115,7 +137,7 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration($format)
115
137
/**
116
138
* @dataProvider getFormats
117
139
*/
118
- public function testLoadDefaultTemplateEscapingGuesserConfiguration ($ format )
140
+ public function testLoadDefaultTemplateEscapingGuesserConfiguration (string $ format )
119
141
{
120
142
$ container = $ this ->createContainer ();
121
143
$ container ->registerExtension (new TwigExtension ());
@@ -129,7 +151,7 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration($format)
129
151
/**
130
152
* @dataProvider getFormats
131
153
*/
132
- public function testLoadCustomDateFormats ($ fileFormat )
154
+ public function testLoadCustomDateFormats (string $ fileFormat )
133
155
{
134
156
$ container = $ this ->createContainer ();
135
157
$ container ->registerExtension (new TwigExtension ());
@@ -178,7 +200,7 @@ public function testGlobalsWithDifferentTypesAndValues()
178
200
/**
179
201
* @dataProvider getFormats
180
202
*/
181
- public function testTwigLoaderPaths ($ format )
203
+ public function testTwigLoaderPaths (string $ format )
182
204
{
183
205
$ container = $ this ->createContainer ();
184
206
$ container ->registerExtension (new TwigExtension ());
@@ -207,7 +229,7 @@ public function testTwigLoaderPaths($format)
207
229
], $ paths );
208
230
}
209
231
210
- public static function getFormats ()
232
+ public static function getFormats (): array
211
233
{
212
234
return [
213
235
['php ' ],
@@ -219,7 +241,7 @@ public static function getFormats()
219
241
/**
220
242
* @dataProvider stopwatchExtensionAvailabilityProvider
221
243
*/
222
- public function testStopwatchExtensionAvailability ($ debug , $ stopwatchEnabled , $ expected )
244
+ public function testStopwatchExtensionAvailability (bool $ debug , bool $ stopwatchEnabled , bool $ expected )
223
245
{
224
246
$ container = $ this ->createContainer ();
225
247
$ container ->setParameter ('kernel.debug ' , $ debug );
@@ -290,7 +312,7 @@ public function testCustomHtmlToTextConverterService(string $format)
290
312
$ this ->assertEquals (new Reference ('my_converter ' ), $ bodyRenderer ->getArgument ('$converter ' ));
291
313
}
292
314
293
- private function createContainer ()
315
+ private function createContainer (): ContainerBuilder
294
316
{
295
317
$ container = new ContainerBuilder (new ParameterBag ([
296
318
'kernel.cache_dir ' => __DIR__ ,
@@ -311,15 +333,15 @@ private function createContainer()
311
333
return $ container ;
312
334
}
313
335
314
- private function compileContainer (ContainerBuilder $ container )
336
+ private function compileContainer (ContainerBuilder $ container ): void
315
337
{
316
338
$ container ->getCompilerPassConfig ()->setOptimizationPasses ([]);
317
339
$ container ->getCompilerPassConfig ()->setRemovingPasses ([]);
318
340
$ container ->getCompilerPassConfig ()->setAfterRemovingPasses ([]);
319
341
$ container ->compile ();
320
342
}
321
343
322
- private function loadFromFile (ContainerBuilder $ container , $ file , $ format )
344
+ private function loadFromFile (ContainerBuilder $ container , string $ file , string $ format ): void
323
345
{
324
346
$ locator = new FileLocator (__DIR__ .'/Fixtures/ ' .$ format );
325
347
0 commit comments