removed support for silent display of undefined blocks

This commit is contained in:
Fabien Potencier
2016-12-05 10:18:56 +01:00
parent 272f792b63
commit b09faf8307
2 changed files with 30 additions and 4 deletions
+2 -4
View File
@@ -175,10 +175,6 @@ abstract class Twig_Template
throw new LogicException('A block must be a method on a Twig_Template instance.');
}
if (!$this->hasBlock($name, $context, $blocks)) {
@trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0.', $name, $this->getTemplateName()), E_USER_DEPRECATED);
}
if (null !== $template) {
try {
$template->$block($context, $blocks);
@@ -200,6 +196,8 @@ abstract class Twig_Template
}
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
} else {
throw new Twig_Error_Runtime(sprintf('Block "%s" on template "%s" does not exist.', $name, $this->getTemplateName()), -1, $this->getTemplateName());
}
}
+28
View File
@@ -128,6 +128,34 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
return $tests;
}
/**
* @expectedException Twig_Error_Runtime
* @expectedExceptionMessage Block "unknown" on template "index.twig" does not exist in "index.twig".
*/
public function testRenderBlockWithUndefinedBlock()
{
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$template = new Twig_TemplateTest($twig, false, 'index.twig');
try {
$template->renderBlock('unknown', array());
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
}
/**
* @expectedException Twig_Error_Runtime
* @expectedExceptionMessage Block "unknown" on template "index.twig" does not exist in "index.twig".
*/
public function testDisplayBlockWithUndefinedBlock()
{
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$template = new Twig_TemplateTest($twig, false, 'index.twig');
$template->displayBlock('unknown', array());
}
/**
* @dataProvider getTestsDependingOnExtensionAvailability
*/