mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-29 19:47:06 +00:00
Merge branch '3.x' into 4.x
* 3.x: Replace `return; yield` with `yield from []` Fix testExtensionsAreNotInitializedWhenRenderingACompiledTemplate Fix MacroTest
This commit is contained in:
@@ -177,19 +177,26 @@ class EnvironmentTest extends TestCase
|
||||
|
||||
// force compilation
|
||||
$twig = new Environment($loader = new ArrayLoader(['index' => '{{ foo }}']), $options);
|
||||
$twig->addExtension($extension = new class extends AbstractExtension {
|
||||
public bool $throw = false;
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
if ($this->throw) {
|
||||
throw new \RuntimeException('Extension are not supposed to be initialized.');
|
||||
}
|
||||
|
||||
return parent::getFilters();
|
||||
}
|
||||
});
|
||||
|
||||
$key = $cache->generateKey('index', $twig->getTemplateClass('index'));
|
||||
$cache->write($key, $twig->compileSource(new Source('{{ foo }}', 'index')));
|
||||
|
||||
// check that extensions won't be initialized when rendering a template that is already in the cache
|
||||
$twig = $this
|
||||
->getMockBuilder(Environment::class)
|
||||
->setConstructorArgs([$loader, $options])
|
||||
->setMethods(['initExtensions'])
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$twig->expects($this->never())->method('initExtensions');
|
||||
$twig = new Environment($loader, $options);
|
||||
$extension->throw = true;
|
||||
$twig->addExtension($extension);
|
||||
|
||||
// render template
|
||||
$output = $twig->render('index', ['foo' => 'bar']);
|
||||
|
||||
Reference in New Issue
Block a user