[Tests] Test accessing a public property when \ArrayAccess is implemented
authorVictor Berchet <victor@suumit.com>
Mon, 30 Jul 2012 15:02:03 +0000 (17:02 +0200)
committerArnaud Le Blanc <arnaud.lb@gmail.com>
Thu, 23 Aug 2012 09:54:31 +0000 (11:54 +0200)
Test case for GH-792

test/Twig/Tests/TemplateTest.php

index 4213e2b..978a5be 100644 (file)
@@ -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()