Fixed templateExists on parse error of the template name

This commit is contained in:
Yonel Ceruto 2018-07-19 11:59:26 -04:00
parent b1f60216a4
commit 53347c42fd
2 changed files with 14 additions and 1 deletions

View File

@ -135,7 +135,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
if ($this->templating instanceof EngineInterface) {
try {
return $this->templating->exists($template);
} catch (\InvalidArgumentException $e) {
} catch (\Exception $e) {
return false;
}
}

View File

@ -86,4 +86,17 @@ class HIncludeFragmentRendererTest extends TestCase
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
}
public function testRenderWithEngineAndDefaultText()
{
$engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock();
$engine->expects($this->once())
->method('exists')
->with('loading...')
->will($this->throwException(new \RuntimeException()));
// only default
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'loading...'))->getContent());
}
}