Skip to content

Commit d888ff3

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: (40 commits) [PropertyInfo] treat mixed[] the same as array when getting types from docblocks treat `mixed[]` the same as `array` when getting types from docblocks install ext-zstd on PHP 8.5 as well fix merge [Console] Fix profile invokable command sync ControllerHelper docblock with latest AbstractController changes fix: Typehint for `createForm` in abstractController [Notifier][Mercure] Add support for Mercure 0.7 register attribute loader arguments in a forward-compatible way ensure compatibility with RelayCluster 0.20.0 mark test using a Redis connection as an integration test ensure compatibility with Relay extension 0.20.0 [FrameworkBundle] Allow backed enum to be used in initial_marking workflow configuration [DependencyInjection] Fix `query_string` env processor for URLs without query string [HttpFoundation] Fix Expires response header for EventStream Bump Symfony version to 7.4.1 Update VERSION for 7.4.0 Update CHANGELOG for 7.4.0 - [DependencyInjection] Fix state corruption in PhpFileLoader during recursive imports ...
2 parents 307d3cf + 245d678 commit d888ff3

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ public function find(string $name): Command
792792
}
793793
}
794794

795-
$command = $this->get(reset($commands));
795+
$command = $commands ? $this->get(reset($commands)) : null;
796796

797-
if ($command->isHidden()) {
797+
if (!$command || $command->isHidden()) {
798798
throw new CommandNotFoundException(\sprintf('The command "%s" does not exist.', $name));
799799
}
800800

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/ApplicationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,21 @@ public function testOriginalHandlerRestoredAfterPop()
26272627
$this->assertSame(\SIG_DFL, pcntl_signal_get_handler(\SIGUSR1), 'OS-level handler must remain SIG_DFL after a second run.');
26282628
}
26292629

2630+
public function testFindAmbiguousHiddenCommands()
2631+
{
2632+
$application = new Application();
2633+
2634+
$application->addCommand(new Command('test:foo'));
2635+
$application->addCommand(new Command('test:foobar'));
2636+
$application->get('test:foo')->setHidden(true);
2637+
$application->get('test:foobar')->setHidden(true);
2638+
2639+
$this->expectException(CommandNotFoundException::class);
2640+
$this->expectExceptionMessage('The command "t:f" does not exist.');
2641+
2642+
$application->find('t:f');
2643+
}
2644+
26302645
#[RequiresPhpExtension('pcntl')]
26312646
#[TestWith([false])]
26322647
#[TestWith([4])]

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)