File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
src/Symfony/Component/Console Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -284,6 +284,10 @@ public function setCode($code)
284284 throw new \InvalidArgumentException ('Invalid callable provided to Command::setCode. ' );
285285 }
286286
287+ if (PHP_VERSION_ID >= 50400 && $ code instanceof \Closure) {
288+ $ code = \Closure::bind ($ code , $ this );
289+ }
290+
287291 $ this ->code = $ code ;
288292
289293 return $ this ;
Original file line number Diff line number Diff line change @@ -293,6 +293,21 @@ public function testSetCode()
293293 $ this ->assertEquals ('interact called ' .PHP_EOL .'from the code... ' .PHP_EOL , $ tester ->getDisplay ());
294294 }
295295
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+ $ tester = new CommandTester ($ command );
307+ $ tester ->execute (array ());
308+ $ this ->assertEquals ('interact called ' .PHP_EOL .'TestCommand ' .PHP_EOL , $ tester ->getDisplay ());
309+ }
310+
296311 public function testSetCodeWithNonClosureCallable ()
297312 {
298313 $ command = new \TestCommand ();
You can’t perform that action at this time.
0 commit comments