Skip to content
This repository
Browse code

Allowing null values to be set and retrieved from Pimple. Adding test…

… coverage.
  • Loading branch information...
commit 3900a1bf26d089916e4bfd1958ddddd49ee4ec34 1 parent 53c82f1
Michael Dowling authored August 15, 2011
2  lib/Pimple.php
@@ -62,7 +62,7 @@ function offsetSet($id, $value)
62 62
      */
63 63
     function offsetGet($id)
64 64
     {
65  
-        if (!isset($this->values[$id])) {
  65
+        if (!array_key_exists($id, $this->values)) {
66 66
             throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
67 67
         }
68 68
 
17  tests/Pimple/Tests/PimpleTest.php
@@ -97,6 +97,23 @@ public function testIsset()
97 97
         $this->assertFalse(isset($pimple['non_existent']));
98 98
     }
99 99
 
  100
+    /**
  101
+     * @expectedException InvalidArgumentException
  102
+     * @expectedExceptionMessage Identifier "foo" is not defined.
  103
+     */
  104
+    public function testOffsetGetValidatesKeyIsPresent()
  105
+    {
  106
+        $pimple = new Pimple();
  107
+        echo $pimple['foo'];
  108
+    }
  109
+
  110
+    public function testOffsetGetHonorsNullValues()
  111
+    {
  112
+        $pimple = new Pimple();
  113
+        $pimple['foo'] = null;
  114
+        $this->assertNull($pimple['foo']);
  115
+    }
  116
+
100 117
     public function testUnset()
101 118
     {
102 119
         $pimple = new Pimple();

0 notes on commit 3900a1b

Please sign in to comment.
Something went wrong with that request. Please try again.