Skip to content

Commit 245d678

Browse files
committed
[Console] Fix profile invokable command
1 parent 0bc0f45 commit 245d678

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Command/TraceableCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
169169
public function setCode(callable $code): static
170170
{
171171
if ($code instanceof InvokableCommand) {
172-
$r = new \ReflectionFunction(\Closure::bind(function () {
173-
return $this->code;
174-
}, $code, InvokableCommand::class)());
172+
$r = \Closure::bind(function () {
173+
return $this->invokable;
174+
}, $code, InvokableCommand::class)();
175175

176176
$this->invokableCommandInfo = [
177177
'class' => $r->getClosureScopeClass()->name,

Tests/Command/TraceableCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\Command\TraceableCommand;
1717
use Symfony\Component\Console\Tester\CommandTester;
18+
use Symfony\Component\Console\Tests\Fixtures\InvokableTestCommand;
1819
use Symfony\Component\Console\Tests\Fixtures\LoopExampleCommand;
1920
use Symfony\Component\Stopwatch\Stopwatch;
2021

@@ -26,6 +27,7 @@ protected function setUp(): void
2627
{
2728
$this->application = new Application();
2829
$this->application->addCommand(new LoopExampleCommand());
30+
$this->application->addCommand(new InvokableTestCommand());
2931
}
3032

3133
public function testRunIsOverriddenWithoutProfile()
@@ -57,6 +59,16 @@ public function testRunIsNotOverriddenWithProfile()
5759
$this->assertLoopOutputCorrectness($output);
5860
}
5961

62+
public function testRunOnInvokableCommand()
63+
{
64+
$command = $this->application->find('invokable:test');
65+
$traceableCommand = new TraceableCommand($command, new Stopwatch());
66+
67+
$commandTester = new CommandTester($traceableCommand);
68+
$commandTester->execute([]);
69+
$commandTester->assertCommandIsSuccessful();
70+
}
71+
6072
public function assertLoopOutputCorrectness(string $output)
6173
{
6274
$completeChar = '\\' !== \DIRECTORY_SEPARATOR ? '' : '=';

0 commit comments

Comments
 (0)