assertFalse($env->isDebug()); $env->addGlobal('global_var', 'global var value'); $env->addGlobal('expect', [ 'ndx_version' => Index::version(), 'twig_version' => TwigEnvironment::VERSION, ]); $env->addFilter('test_filter', fn(string $text) => ('filter:' . $text)); $env->addFunction('test_function', fn(string $text) => ('func:' . $text)); $env->addTest('test_test', fn(string $text) => $text === 'test'); $rendered = $env->render('TemplatingTest-rendered', [ 'local_var' => 'this var is local', ]); $this->assertEquals(file_get_contents(__DIR__ . '/TemplatingTest-rendered.html'), $rendered); $ctx = $env->load('TemplatingTest-loaded', [ 'context_var' => 'this var is context', 'variant' => 'toString()', ]); $ctx->setVar('simple_set', 'simple set call'); $ctx->setVar('another.context.var.deep', 'applied with fuckery'); $ctx->setVars([ 'context_var2' => 'applied without fuckery', ]); $loaded = $ctx->render([ 'local_var' => 'this var is local', 'variant' => 'render()', ]); $this->assertEquals(file_get_contents(__DIR__ . '/TemplatingTest-loaded-render.html'), $loaded); $this->assertEquals(file_get_contents(__DIR__ . '/TemplatingTest-loaded-string.html'), (string)$ctx); } }