File tree 2 files changed +20
-0
lines changed
src/Symfony/Component/Console
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -284,6 +284,10 @@ public function setCode($code)
284
284
throw new \InvalidArgumentException ('Invalid callable provided to Command::setCode. ' );
285
285
}
286
286
287
+ if (PHP_VERSION_ID >= 50400 && $ code instanceof \Closure) {
288
+ $ code = \Closure::bind ($ code , $ this );
289
+ }
290
+
287
291
$ this ->code = $ code ;
288
292
289
293
return $ this ;
Original file line number Diff line number Diff line change @@ -293,6 +293,22 @@ public function testSetCode()
293
293
$ this ->assertEquals ('interact called ' .PHP_EOL .'from the code... ' .PHP_EOL , $ tester ->getDisplay ());
294
294
}
295
295
296
+ public function testSetCodeBindToClosure ()
297
+ {
298
+ if (PHP_VERSION_ID < 50400 ) {
299
+ $ this ->markTestSkipped ('Test skipped, for PHP 5.4+ only. ' );
300
+ }
301
+
302
+ $ command = new \TestCommand ();
303
+ $ ret = $ command ->setCode (function (InputInterface $ input , OutputInterface $ output ) {
304
+ $ output ->writeln (get_class ($ this ));
305
+ });
306
+ $ this ->assertEquals ($ command , $ ret , '->setCode() implements a fluent interface ' );
307
+ $ tester = new CommandTester ($ command );
308
+ $ tester ->execute (array ());
309
+ $ this ->assertEquals ('interact called ' .PHP_EOL .'TestCommand ' .PHP_EOL , $ tester ->getDisplay ());
310
+ }
311
+
296
312
public function testSetCodeWithNonClosureCallable ()
297
313
{
298
314
$ command = new \TestCommand ();
You can’t perform that action at this time.
0 commit comments