Merge branch '4.4' into 5.1
* 4.4: "export-ignore" contracts and phpunit-bridge [Console][Command] Fix Closure code binding when it is a static anonymous function
This commit is contained in:
commit
a933c3e0a1
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/src/Symfony/Contracts export-ignore
|
||||
/src/Symfony/Bridge/PhpUnit export-ignore
|
@ -285,7 +285,14 @@ class Command
|
||||
if ($code instanceof \Closure) {
|
||||
$r = new \ReflectionFunction($code);
|
||||
if (null === $r->getClosureThis()) {
|
||||
$code = \Closure::bind($code, $this);
|
||||
set_error_handler(static function () {});
|
||||
try {
|
||||
if ($c = \Closure::bind($code, $this)) {
|
||||
$code = $c;
|
||||
}
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,6 +391,18 @@ class CommandTest extends TestCase
|
||||
{
|
||||
$output->writeln('from the code...');
|
||||
}
|
||||
|
||||
public function testSetCodeWithStaticAnonymousFunction()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$command->setCode(static function (InputInterface $input, OutputInterface $output) {
|
||||
$output->writeln(isset($this) ? 'bound' : 'not bound');
|
||||
});
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertEquals('interact called'.\PHP_EOL.'not bound'.\PHP_EOL, $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
// In order to get an unbound closure, we should create it outside a class
|
||||
|
Reference in New Issue
Block a user