mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
added tests for exceptions thrown in __call()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.15.0 (2013-XX-XX)
|
||||
|
||||
* made ignoreStrictCheck in Template::getAttribute() works with __call() methods throwing BadMethodCallException
|
||||
* added the round filter
|
||||
* fixed a bug that prevented the optimizers to be enabled/disabled selectively
|
||||
* fixed first and last filters for UTF-8 strings
|
||||
|
||||
@@ -417,6 +417,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object)));
|
||||
}
|
||||
|
||||
$call = false;
|
||||
$lcItem = strtolower($item);
|
||||
if (isset(self::$cache[$class]['methods'][$lcItem])) {
|
||||
$method = (string) $item;
|
||||
@@ -426,6 +427,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
$method = 'is'.$item;
|
||||
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
|
||||
$method = (string) $item;
|
||||
$call = true;
|
||||
} else {
|
||||
if ($isDefinedTest) {
|
||||
return false;
|
||||
@@ -450,8 +452,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
// to call is not supported. If ignoreStrictCheck is true, we should return null.
|
||||
try {
|
||||
$ret = call_user_func_array(array($object, $method), $arguments);
|
||||
} catch (\BadMethodCallException $e) {
|
||||
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
||||
} catch (BadMethodCallException $e) {
|
||||
if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
|
||||
return null;
|
||||
}
|
||||
throw $e;
|
||||
|
||||
@@ -236,6 +236,18 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestsDependingOnExtensionAvailability
|
||||
*/
|
||||
public function testGetAttributeCallExceptions($useExt = false)
|
||||
{
|
||||
$template = new Twig_TemplateTest(new Twig_Environment(), $useExt);
|
||||
|
||||
$object = new Twig_TemplateMagicMethodExceptionObject();
|
||||
|
||||
$this->assertEquals(null, $template->getAttribute($object, 'foo'));
|
||||
}
|
||||
|
||||
public function getGetAttributeTests()
|
||||
{
|
||||
$array = array(
|
||||
@@ -603,6 +615,14 @@ class Twig_TemplateMagicMethodObject
|
||||
}
|
||||
}
|
||||
|
||||
class Twig_TemplateMagicMethodExceptionObject
|
||||
{
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
throw new BadMethodCallException(sprintf('Unkown method %s', $method));
|
||||
}
|
||||
}
|
||||
|
||||
class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface
|
||||
{
|
||||
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
|
||||
|
||||
Reference in New Issue
Block a user