Permalink
Browse files

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

… coverage.
  • Loading branch information...
1 parent 53c82f1 commit 3900a1bf26d089916e4bfd1958ddddd49ee4ec34 @mtdowling mtdowling committed Aug 16, 2011
Showing with 18 additions and 1 deletion.
  1. +1 −1 lib/Pimple.php
  2. +17 −0 tests/Pimple/Tests/PimpleTest.php
View
@@ -62,7 +62,7 @@ function offsetSet($id, $value)
*/
function offsetGet($id)
{
- if (!isset($this->values[$id])) {
+ if (!array_key_exists($id, $this->values)) {
throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
}
@@ -97,6 +97,23 @@ public function testIsset()
$this->assertFalse(isset($pimple['non_existent']));
}
+ /**
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Identifier "foo" is not defined.
+ */
+ public function testOffsetGetValidatesKeyIsPresent()
+ {
+ $pimple = new Pimple();
+ echo $pimple['foo'];
+ }
+
+ public function testOffsetGetHonorsNullValues()
+ {
+ $pimple = new Pimple();
+ $pimple['foo'] = null;
+ $this->assertNull($pimple['foo']);
+ }
+
public function testUnset()
{
$pimple = new Pimple();

0 comments on commit 3900a1b

Please sign in to comment.