@@ -64,11 +64,11 @@ public function testLoadEmptyConfiguration()
64
64
}
65
65
66
66
/**
67
- * @dataProvider getFormats
67
+ * @dataProvider getFormatsAndBuildDir
68
68
*/
69
- public function testLoadFullConfiguration (string $ format )
69
+ public function testLoadFullConfiguration (string $ format, ? string $ buildDir )
70
70
{
71
- $ container = $ this ->createContainer ();
71
+ $ container = $ this ->createContainer ($ buildDir );
72
72
$ container ->registerExtension (new TwigExtension ());
73
73
$ this ->loadFromFile ($ container , 'full ' , $ format );
74
74
$ this ->compileContainer ($ container );
@@ -99,13 +99,64 @@ public function testLoadFullConfiguration(string $format)
99
99
100
100
// Twig options
101
101
$ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
102
- $ this ->assertTrue ($ options ['auto_reload ' ], '->load() sets the auto_reload option ' );
102
+ $ this ->assertFalse ($ options ['auto_reload ' ], '->load() sets the auto_reload option ' );
103
103
$ this ->assertSame ('name ' , $ options ['autoescape ' ], '->load() sets the autoescape option ' );
104
104
$ this ->assertArrayNotHasKey ('base_template_class ' , $ options , '->load() does not set the base_template_class if none is provided ' );
105
- $ this ->assertEquals ('/tmp ' , $ options ['cache ' ], '->load() sets the cache option ' );
106
105
$ this ->assertEquals ('ISO-8859-1 ' , $ options ['charset ' ], '->load() sets the charset option ' );
107
106
$ this ->assertTrue ($ options ['debug ' ], '->load() sets the debug option ' );
108
107
$ this ->assertTrue ($ options ['strict_variables ' ], '->load() sets the strict_variables option ' );
108
+ $ this ->assertEquals ($ buildDir !== null ? new Reference ('twig.template_cache.chain ' ) : '%kernel.cache_dir%/twig ' , $ options ['cache ' ], '->load() sets the cache option ' );
109
+ }
110
+
111
+ /**
112
+ * @dataProvider getFormatsAndBuildDir
113
+ */
114
+ public function testLoadNoCacheConfiguration (string $ format , ?string $ buildDir )
115
+ {
116
+ $ container = $ this ->createContainer ($ buildDir );
117
+ $ container ->registerExtension (new TwigExtension ());
118
+ $ this ->loadFromFile ($ container , 'no-cache ' , $ format );
119
+ $ this ->compileContainer ($ container );
120
+
121
+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
122
+
123
+ // Twig options
124
+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
125
+ $ this ->assertFalse ($ options ['cache ' ], '->load() sets cache option to false ' );
126
+ }
127
+
128
+ /**
129
+ * @dataProvider getFormatsAndBuildDir
130
+ */
131
+ public function testLoadPathCacheConfiguration (string $ format , ?string $ buildDir )
132
+ {
133
+ $ container = $ this ->createContainer ($ buildDir );
134
+ $ container ->registerExtension (new TwigExtension ());
135
+ $ this ->loadFromFile ($ container , 'path-cache ' , $ format );
136
+ $ this ->compileContainer ($ container );
137
+
138
+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
139
+
140
+ // Twig options
141
+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
142
+ $ this ->assertSame ('random-path ' , $ options ['cache ' ], '->load() sets cache option to string path ' );
143
+ }
144
+
145
+ /**
146
+ * @dataProvider getFormatsAndBuildDir
147
+ */
148
+ public function testLoadProdCacheConfiguration (string $ format , ?string $ buildDir )
149
+ {
150
+ $ container = $ this ->createContainer ($ buildDir );
151
+ $ container ->registerExtension (new TwigExtension ());
152
+ $ this ->loadFromFile ($ container , 'prod-cache ' , $ format );
153
+ $ this ->compileContainer ($ container );
154
+
155
+ $ this ->assertEquals (Environment::class, $ container ->getDefinition ('twig ' )->getClass (), '->load() loads the twig.xml file ' );
156
+
157
+ // Twig options
158
+ $ options = $ container ->getDefinition ('twig ' )->getArgument (1 );
159
+ $ this ->assertEquals ($ buildDir !== null ? new Reference ('twig.template_cache.chain ' ) : '%kernel.cache_dir%/twig ' , $ options ['cache ' ], '->load() sets cache option to CacheChain reference ' );
109
160
}
110
161
111
162
/**
@@ -245,6 +296,19 @@ public static function getFormats(): array
245
296
];
246
297
}
247
298
299
+ public static function getFormatsAndBuildDir (): array
300
+ {
301
+ return [
302
+ ['php ' , null ],
303
+ ['php ' , __DIR__ .'/build ' ],
304
+ ['yml ' , null ],
305
+ ['yml ' , __DIR__ .'/build ' ],
306
+ ['xml ' , null ],
307
+ ['xml ' , __DIR__ .'/build ' ],
308
+ ];
309
+ }
310
+
311
+
248
312
/**
249
313
* @dataProvider stopwatchExtensionAvailabilityProvider
250
314
*/
@@ -319,10 +383,11 @@ public function testCustomHtmlToTextConverterService(string $format)
319
383
$ this ->assertEquals (new Reference ('my_converter ' ), $ bodyRenderer ->getArgument ('$converter ' ));
320
384
}
321
385
322
- private function createContainer (): ContainerBuilder
386
+ private function createContainer (? string $ buildDir = null ): ContainerBuilder
323
387
{
324
388
$ container = new ContainerBuilder (new ParameterBag ([
325
389
'kernel.cache_dir ' => __DIR__ ,
390
+ 'kernel.build_dir ' => $ buildDir ?? __DIR__ ,
326
391
'kernel.project_dir ' => __DIR__ ,
327
392
'kernel.charset ' => 'UTF-8 ' ,
328
393
'kernel.debug ' => false ,
0 commit comments