Skip to content

Commit

Permalink
Merge branch '5.1' into 5.2
Browse files Browse the repository at this point in the history
* 5.1:
  "export-ignore" contracts and phpunit-bridge
  [Console][Command] Fix Closure code binding when it is a static anonymous function
  Use class const in test
  [Security] [HttpFoundation] Use class const in test
  [PropertyInfo] Fix breaking change with has*(arguments...) methods
  • Loading branch information
xabbuh committed Jan 23, 2021
2 parents 08ceb3a + 7db4781 commit c525b23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,14 @@ public function setCode(callable $code)
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();
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,18 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou
{
$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
Expand Down
6 changes: 2 additions & 4 deletions Tests/Logger/ConsoleLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;

/**
* Console logger test.
*
* @author Kévin Dunglas <[email protected]>
* @author Jordi Boggiano <[email protected]>
*/
Expand Down Expand Up @@ -157,9 +155,9 @@ public function testContextReplacement()
public function testObjectCastToString()
{
if (method_exists($this, 'createPartialMock')) {
$dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']);
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
} else {
$dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']);
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
}
$dummy->method('__toString')->willReturn('DUMMY');

Expand Down

0 comments on commit c525b23

Please sign in to comment.