Permalink
Browse files

Check definition is actually a Closure

  • Loading branch information...
davedevelopment committed Mar 31, 2012
1 parent 7367dca commit 6677eeb4c76520bbfec231a6d183b8779b36d418
Showing with 26 additions and 0 deletions.
  1. +5 −0 lib/Pimple.php
  2. +21 −0 tests/Pimple/Tests/PimpleTest.php
View
@@ -179,6 +179,11 @@ function extend($id, Closure $callable)
}
$factory = $this->values[$id];
+
+ if (!($factory instanceof Closure)) {
+ throw new InvalidArgumentException(sprintf('Identifier "%s" does not contain an object definition.', $id));
+ }
+
return $this->values[$id] = function ($c) use ($callable, $factory) {
return $callable($factory($c), $c);
};
@@ -215,4 +215,25 @@ public function testExtend()
$this->assertSame($serviceOne, $serviceTwo);
}
+
+ /**
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Identifier "foo" is not defined.
+ */
+ public function testExtendValidatesKeyIsPresent()
+ {
+ $pimple = new Pimple();
+ $pimple->extend('foo', function () {});
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Identifier "foo" does not contain an object definition.
+ */
+ public function testExtendValidatesKeyYieldsObjectDefinition()
+ {
+ $pimple = new Pimple();
+ $pimple['foo'] = 123;
+ $pimple->extend('foo', function () {});
+ }
}

0 comments on commit 6677eeb

Please sign in to comment.