$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'
) ->
willReturnMap([ [ImportMapRuntime::
class,
$runtime],
]) ;
$twig->
addRuntimeLoader($mockRuntimeLoader);
$this->
assertSame($expected,
$twig->
render('template'
));
}