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());
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());
+ }
}
}
*/
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
*/