Use the decorated parser if bundle does not exist

This commit is contained in:
Edi Modrić 2017-06-21 11:22:31 +02:00 committed by Edi Modrić
parent 9f1cb34ef3
commit e934fd095a
2 changed files with 10 additions and 5 deletions

View file

@ -76,7 +76,7 @@ final class TemplateNameParser implements TemplateNameParserInterface
try {
$this->kernel->getBundle($template->get('bundle'));
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
return $this->decoratedParser->parse($name);
}
}

View file

@ -63,11 +63,16 @@ final class TemplateNameParserSpec extends ObjectBehavior
$this->parse('@Acme/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Nested/Directory', 'app', 'html', 'twig'));
}
function it_throws_an_exception_if_namespaced_path_references_not_existing_bundle(KernelInterface $kernel)
{
$kernel->getBundle('AcmeBundle')->willThrow(\Exception::class);
function it_delegates_custom_namespace_to_decorated_parser(
KernelInterface $kernel,
TemplateNameParserInterface $decoratedParser,
TemplateReferenceInterface $templateReference
) {
$kernel->getBundle('myBundle')->willThrow(\Exception::class);
$this->shouldThrow(\InvalidArgumentException::class)->during('parse', ['@Acme/app.html.twig']);
$decoratedParser->parse('@my/custom/namespace.html.twig')->willReturn($templateReference);
$this->parse('@my/custom/namespace.html.twig')->shouldReturn($templateReference);
}
function it_generates_template_references_from_root_namespaced_paths()