Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Check definition is actually a Closure

  • Loading branch information...
commit 6677eeb4c76520bbfec231a6d183b8779b36d418 1 parent 7367dca
Dave Marshall authored April 01, 2012
5  lib/Pimple.php
@@ -179,6 +179,11 @@ function extend($id, Closure $callable)
179 179
         }
180 180
 
181 181
         $factory = $this->values[$id];
  182
+
  183
+        if (!($factory instanceof Closure)) {
  184
+            throw new InvalidArgumentException(sprintf('Identifier "%s" does not contain an object definition.', $id));
  185
+        }
  186
+
182 187
         return $this->values[$id] = function ($c) use ($callable, $factory) {
183 188
             return $callable($factory($c), $c);
184 189
         };
21  tests/Pimple/Tests/PimpleTest.php
@@ -215,4 +215,25 @@ public function testExtend()
215 215
 
216 216
         $this->assertSame($serviceOne, $serviceTwo);
217 217
     }
  218
+
  219
+    /**
  220
+     * @expectedException InvalidArgumentException
  221
+     * @expectedExceptionMessage Identifier "foo" is not defined.
  222
+     */
  223
+    public function testExtendValidatesKeyIsPresent()
  224
+    {
  225
+        $pimple = new Pimple();
  226
+        $pimple->extend('foo', function () {});
  227
+    }
  228
+
  229
+    /**
  230
+     * @expectedException InvalidArgumentException
  231
+     * @expectedExceptionMessage Identifier "foo" does not contain an object definition.
  232
+     */
  233
+    public function testExtendValidatesKeyYieldsObjectDefinition()
  234
+    {
  235
+        $pimple = new Pimple();
  236
+        $pimple['foo'] = 123;
  237
+        $pimple->extend('foo', function () {});
  238
+    }
218 239
 }

0 notes on commit 6677eeb

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