ImportMapExtension example

use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\RuntimeLoader\RuntimeLoaderInterface;

class ImportMapExtensionTest extends TestCase
{
    public function testItRendersTheImportmap()
    {
        $twig = new Environment(new ArrayLoader([
            'template' => '{{ importmap("application") }}',
        ])['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);
        $twig->addExtension(new ImportMapExtension());
        $importMapRenderer = $this->createMock(ImportMapRenderer::class);
        $expected = '<script type="importmap">{ "imports": {}}</script>';
        $importMapRenderer->expects($this->once())
            ->method('render')
            ->with('application')
            ->willReturn($expected);
        $runtime = new ImportMapRuntime($importMapRenderer);

        $mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);
        $mockRuntimeLoader
            ->method('load')
            
Home | Imprint | This part of the site doesn't use cookies.