Explorar el Código

Clean up code style, ArrayAccess test.

See #178
Justin Hileman hace 12 años
padre
commit
04b016016e
Se han modificado 2 ficheros con 29 adiciones y 11 borrados
  1. 2 1
      src/Mustache/Context.php
  2. 27 10
      test/Mustache/Test/ContextTest.php

+ 2 - 1
src/Mustache/Context.php

@@ -134,7 +134,7 @@ class Mustache_Context
     {
         for ($i = count($stack) - 1; $i >= 0; $i--) {
             if (is_object($stack[$i])) {
-                if( $stack[$i] instanceof ArrayAccess) {
+                if ($stack[$i] instanceof ArrayAccess) {
                     if (isset($stack[$i][$id])) {
                         return $stack[$i][$id];
                     }
@@ -149,6 +149,7 @@ class Mustache_Context
                 return $stack[$i][$id];
             }
         }
+
         return '';
     }
 }

+ 27 - 10
test/Mustache/Test/ContextTest.php

@@ -71,8 +71,6 @@ class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase
 
         $string = 'some arbitrary string';
 
-        $access = new Mustache_Test_TestArrayAccess($arr);
-
         $context->push($dummy);
         $this->assertEquals('dummy', $context->find('name'));
 
@@ -97,8 +95,16 @@ class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('see', $context->findDot('a.b.c'));
         $this->assertEquals('<foo>', $context->find('foo'));
         $this->assertEquals('<bar>', $context->findDot('bar'));
+    }
 
-        $context = new Mustache_Context($arr);
+    public function testArrayAccessFind()
+    {
+        $access = new Mustache_Test_TestArrayAccess(array(
+            'a' => array('b' => array('c' => 'see')),
+            'b' => 'bee',
+        ));
+
+        $context = new Mustache_Context($access);
         $this->assertEquals('bee', $context->find('b'));
         $this->assertEquals('see', $context->findDot('a.b.c'));
         $this->assertEquals(null, $context->findDot('a.b.c.d'));
@@ -125,27 +131,38 @@ class Mustache_Test_TestDummy
     }
 }
 
-class Mustache_Test_TestArrayAccess  implements arrayaccess {
+class Mustache_Test_TestArrayAccess implements ArrayAccess
+{
     private $container = array();
-    public function __construct($array) {
-        foreach($array as $key => $value) {
+
+    public function __construct($array)
+    {
+        foreach ($array as $key => $value) {
             $this->container[$key] = $value;
         }
     }
-    public function offsetSet($offset, $value) {
+
+    public function offsetSet($offset, $value)
+    {
         if (is_null($offset)) {
             $this->container[] = $value;
         } else {
             $this->container[$offset] = $value;
         }
     }
-    public function offsetExists($offset) {
+
+    public function offsetExists($offset)
+    {
         return isset($this->container[$offset]);
     }
-    public function offsetUnset($offset) {
+
+    public function offsetUnset($offset)
+    {
         unset($this->container[$offset]);
     }
-    public function offsetGet($offset) {
+
+    public function offsetGet($offset)
+    {
         return isset($this->container[$offset]) ? $this->container[$offset] : null;
     }
 }