mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 21:07:18 +00:00
removed support for silent display of undefined blocks
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user