HttpKernelExtension example

$fragmentHandler = new FragmentHandler($requestStack);
        $fragmentUriGenerator = new FragmentUriGenerator('/_fragment', new UriSigner('s3cr3t')$requestStack);

        $kernelRuntime = new HttpKernelRuntime($fragmentHandler$fragmentUriGenerator);

        $loader = new ArrayLoader([
            '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)
    {
Home | Imprint | This part of the site doesn't use cookies.