protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
 {
     $loader = new \Twig_Loader_Array(array('index' => $template));
     $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
     $twig->addExtension(new HttpKernelExtension());
     $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
     $loader->expects($this->any())->method('load')->will($this->returnValueMap(array(array('Symfony\\Bridge\\Twig\\Extension\\HttpKernelRuntime', new HttpKernelRuntime($renderer)))));
     $twig->addRuntimeLoader($loader);
     return $twig->render('index');
 }
 protected function setUp()
 {
     parent::setUp();
     $loader = new \Twig_Loader_Filesystem([__DIR__ . '/../../Resources/theme', __DIR__ . '/../Resources/views']);
     $environment = new \Twig_Environment($loader, ['debug' => true, 'strict_variables' => true]);
     $environment->addGlobal('global_var', 'global_value');
     $environment->addExtension(new DatagridExtension());
     $rendererEngine = new TwigRendererEngine($environment, ['datagrid.html.twig']);
     $this->renderer = new TwigRenderer($rendererEngine);
     $loader = $this->prophesize(\Twig_RuntimeLoaderInterface::class);
     $loader->load(TwigRenderer::class)->willReturn($this->renderer);
     $environment->addRuntimeLoader($loader->reveal());
     $this->twig = $environment;
 }
 protected function setUp()
 {
     parent::setUp();
     $loader = new \Twig_Loader_Filesystem([__DIR__ . '/../../Resources/theme']);
     $cacheDir = __DIR__ . '/twig-perf';
     if (!file_exists($cacheDir)) {
         @mkdir($cacheDir);
     }
     $environment = new \Twig_Environment($loader, ['debug' => true, 'strict_variables' => true, 'cache' => $cacheDir]);
     $environment->addExtension(new DatagridExtension());
     $rendererEngine = new TwigRendererEngine($environment, ['datagrid.html.twig']);
     $this->renderer = new TwigRenderer($rendererEngine);
     $loader = $this->prophesize(\Twig_RuntimeLoaderInterface::class);
     $loader->load(TwigRenderer::class)->willReturn($this->renderer);
     $environment->addRuntimeLoader($loader->reveal());
     // load the theme template to ensure a compile, we are only interested in the rendering speed
     $environment->loadTemplate('datagrid.html.twig');
 }
 protected function registerTwigRuntimeLoader(\Twig_Environment $environment, TwigRenderer $renderer)
 {
     $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
     $loader->expects($this->any())->method('load')->will($this->returnValueMap(array(array('Symfony\\Bridge\\Twig\\Form\\TwigRenderer', $renderer))));
     $environment->addRuntimeLoader($loader);
 }
 public function testAddRuntimeLoader()
 {
     $runtimeLoader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
     $runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime()));
     $loader = new Twig_Loader_Array(array('func_array' => '{{ from_runtime_array("foo") }}', 'func_array_default' => '{{ from_runtime_array() }}', 'func_array_named_args' => '{{ from_runtime_array(name="foo") }}', 'func_string' => '{{ from_runtime_string("foo") }}', 'func_string_default' => '{{ from_runtime_string() }}', 'func_string_named_args' => '{{ from_runtime_string(name="foo") }}'));
     $twig = new Twig_Environment($loader);
     $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime());
     $twig->addRuntimeLoader($runtimeLoader);
     $this->assertEquals('foo', $twig->render('func_array'));
     $this->assertEquals('bar', $twig->render('func_array_default'));
     $this->assertEquals('foo', $twig->render('func_array_named_args'));
     $this->assertEquals('foo', $twig->render('func_string'));
     $this->assertEquals('bar', $twig->render('func_string_default'));
     $this->assertEquals('foo', $twig->render('func_string_named_args'));
 }
 protected function getTwigService()
 {
     $a = $this->get('request_stack');
     $b = new \Symfony\Bridge\Twig\AppVariable();
     $b->setEnvironment('prod');
     $b->setDebug(false);
     if ($this->has('security.token_storage')) {
         $b->setTokenStorage($this->get('security.token_storage', ContainerInterface::NULL_ON_INVALID_REFERENCE));
     }
     if ($this->has('request_stack')) {
         $b->setRequestStack($a);
     }
     $this->services['twig'] = $instance = new \Twig_Environment($this->get('twig.loader'), array('debug' => false, 'strict_variables' => false, 'exception_controller' => 'twig.controller.exception:showAction', 'form_themes' => array(0 => 'form_div_layout.html.twig'), 'autoescape' => 'name', 'cache' => __DIR__ . '/twig', 'charset' => 'UTF-8', 'paths' => array(), 'date' => array('format' => 'F j, Y H:i', 'interval_format' => '%d days', 'timezone' => NULL), 'number_format' => array('decimals' => 0, 'decimal_point' => '.', 'thousands_separator' => ',')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\LogoutUrlExtension(${($_ = isset($this->services['security.logout_url_generator']) ? $this->services['security.logout_url_generator'] : $this->getSecurity_LogoutUrlGeneratorService()) && false ?: '_'}));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\SecurityExtension($this->get('security.authorization_checker', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension($this->get('translator')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\AssetExtension($this->get('assets.packages')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\CodeExtension(${($_ = isset($this->services['debug.file_link_formatter']) ? $this->services['debug.file_link_formatter'] : $this->getDebug_FileLinkFormatterService()) && false ?: '_'}, $this->targetDirs[3] . '/app', 'UTF-8'));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\RoutingExtension($this->get('router')));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\YamlExtension());
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\StopwatchExtension($this->get('debug.stopwatch', ContainerInterface::NULL_ON_INVALID_REFERENCE), false));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\ExpressionExtension());
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\HttpKernelExtension());
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\HttpFoundationExtension($a, ${($_ = isset($this->services['router.request_context']) ? $this->services['router.request_context'] : $this->getRouter_RequestContextService()) && false ?: '_'}));
     $instance->addExtension(new \Symfony\Bridge\Twig\Extension\FormExtension());
     $instance->addExtension($this->get('propel.twig.extension.syntax'));
     $instance->addGlobal('app', $b);
     $instance->addRuntimeLoader(new \Symfony\Bundle\TwigBundle\ContainerAwareRuntimeLoader($this, array('Symfony\\Bridge\\Twig\\Extension\\HttpKernelRuntime' => 'twig.runtime.httpkernel', 'Symfony\\Bridge\\Twig\\Form\\TwigRenderer' => 'twig.form.renderer'), $this->get('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
     (new \Symfony\Bundle\TwigBundle\DependencyInjection\Configurator\EnvironmentConfigurator('F j, Y H:i', '%d days', NULL, 0, '.', ','))->configure($instance);
     return $instance;
 }