addRuntimeLoader example

$mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);
        $mockRuntimeLoader
            ->method('load')
            ->willReturnMap([
                ['Symfony\Bridge\Twig\Extension\SerializerRuntime', $runtime],
            ])
        ;

        $twig = new Environment(new ArrayLoader(['template' => $template]));
        $twig->addExtension(new SerializerExtension());
        $twig->addRuntimeLoader($mockRuntimeLoader);

        return $twig;
    }
}
$loader = new ArrayLoader($templates);

        foreach ($outputs as $i => $match) {
            $config = array_merge([
                'cache' => false,
                'strict_variables' => true,
            ]$match[2] ? eval($match[2].';') : []);
            $twig = new Environment($loader$config);
            $twig->addGlobal('global', 'global');
            foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
                $twig->addRuntimeLoader($runtimeLoader);
            }

            foreach ($this->getExtensions() as $extension) {
                $twig->addExtension($extension);
            }

            foreach ($this->getTwigFilters() as $filter) {
                $twig->addFilter($filter);
            }

            foreach ($this->getTwigTests() as $test) {
                
->with('application')
            ->willReturn($expected);
        $runtime = new ImportMapRuntime($importMapRenderer);

        $mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);
        $mockRuntimeLoader
            ->method('load')
            ->willReturnMap([
                [ImportMapRuntime::class$runtime],
            ])
        ;
        $twig->addRuntimeLoader($mockRuntimeLoader);

        $this->assertSame($expected$twig->render('template'));
    }
}
'index' => sprintf(<<<TWIG {{ fragment_uri(controller("%s::templateAction", {template: "foo.html.twig"})) }} TWIG
                , TemplateController::class)]);
        $twig = new Environment($loader['debug' => true, 'cache' => false]);
        $twig->addExtension(new HttpKernelExtension());

        $loader = $this->createMock(RuntimeLoaderInterface::class);
        $loader->expects($this->any())->method('load')->willReturnMap([
            [HttpKernelRuntime::class$kernelRuntime],
        ]);
        $twig->addRuntimeLoader($loader);

        $this->assertSame('/_fragment?_hash=PP8%2FeEbn1pr27I9wmag%2FM6jYGVwUZ0l2h0vhh2OJ6CI%3D&amp;_path=template%3Dfoo.html.twig%26_format%3Dhtml%26_locale%3Den%26_controller%3DSymfonyBundleFrameworkBundleControllerTemplateController%253A%253AtemplateAction', $twig->render('index'));
    }

    protected function getFragmentHandler($return)
    {
        $strategy = $this->createMock(FragmentRendererInterface::class);
        $strategy->expects($this->once())->method('getName')->willReturn('inline');
        $strategy->expects($this->once())->method('render')->will($return);

        $context = $this->createMock(RequestStack::class);

        
use Twig\Environment;
use Twig\RuntimeLoader\RuntimeLoaderInterface;

trait RuntimeLoaderProvider
{
    protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer)
    {
        $loader = $this->createMock(RuntimeLoaderInterface::class);
        $loader->expects($this->any())->method('load')->will($this->returnValueMap([
            ['Symfony\Component\Form\FormRenderer', $renderer],
        ]));
        $environment->addRuntimeLoader($loader);
    }
}
Home | Imprint | This part of the site doesn't use cookies.