mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
improved error messages
This commit is contained in:
committed by
Fabien Potencier
parent
4c237b2253
commit
024b9367eb
@@ -344,7 +344,7 @@ class Twig_ExpressionParser
|
||||
while (true) {
|
||||
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
||||
if (in_array($token->getValue(), array('true', 'false', 'none'))) {
|
||||
throw new Twig_Error_Syntax($token->getValue() . ' cannot be assigned to');
|
||||
throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s"', $token->getValue()));
|
||||
}
|
||||
$targets[] = new Twig_Node_Expression_AssignName($token->getValue(), $token->getLine());
|
||||
|
||||
|
||||
@@ -128,7 +128,12 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" for array "%s" does not exist', $item, $object), -1, $this->getTemplateName());
|
||||
if (is_object($object)) {
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
|
||||
// array
|
||||
} else {
|
||||
throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))), -1, $this->getTemplateName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,28 @@
|
||||
*/
|
||||
class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getUnkownPropertyOnArrayTests()
|
||||
{
|
||||
$tests = array(
|
||||
array(array('foo' => 'foo', 'bar' => 'value')),
|
||||
array(new Twig_TemplateObjectArrayAccess()),
|
||||
);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getUnkownPropertyOnArrayTests
|
||||
* @expectedException Twig_Error_Runtime
|
||||
*/
|
||||
public function testUnkownPropertyOnArray($array)
|
||||
{
|
||||
$env = new Twig_Environment(null, array('strict_variables' => true));
|
||||
$template = new Twig_TemplateTest($env);
|
||||
|
||||
$template->getAttribute($array, 'unknown', array(), Twig_Node_Expression_GetAttr::TYPE_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getGetAttributeTests
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user