From d6fc86a8456177cc68f50b2e7aa5034bddc0afa9 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 30 Jul 2012 17:02:03 +0200 Subject: [PATCH] [Tests] Test accessing a public property when \ArrayAccess is implemented Test case for GH-792 --- test/Twig/Tests/TemplateTest.php | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 4213e2b..978a5be 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -102,6 +102,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $magicPropertyObject = new Twig_TemplateMagicPropertyObject(); $propertyObject = new Twig_TemplatePropertyObject(); $propertyObject1 = new Twig_TemplatePropertyObjectAndIterator(); + $propertyObject2 = new Twig_TemplatePropertyObjectAndArrayAccess(); $methodObject = new Twig_TemplateMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject(); @@ -129,6 +130,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase array($methodObject, $anyType), array($propertyObject, $anyType), array($propertyObject1, $anyType), + array($propertyObject2, $anyType), ); $tests = array(); @@ -318,6 +320,29 @@ class Twig_TemplatePropertyObjectAndIterator extends Twig_TemplatePropertyObject } } +class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObject implements \ArrayAccess +{ + private $data = array(); + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->data[$offset] : 'n/a'; + } + + public function offsetSet($offset, $value) + { + } + + public function offsetUnset($offset) + { + } +} + class Twig_TemplateMethodObject { public function getDefined() -- 1.7.2.5