Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CHANGELOG
* Add `#[MapInput]` attribute to support DTOs in commands
* Add optional timeout for interaction in `QuestionHelper`
* Add support for interactive invokable commands with `#[Interact]` and `#[Ask]` attributes
* Add support for `Cursor` helper in invokable commands

7.3
---
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Console/Command/InvokableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Attribute\Interact;
use Symfony\Component\Console\Attribute\MapInput;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Cursor;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -174,6 +175,7 @@ private function getParameters(\ReflectionFunction $function, InputInterface $in
$parameters[] = match ($type->getName()) {
InputInterface::class => $input,
OutputInterface::class => $output,
Cursor::class => new Cursor($output),
SymfonyStyle::class => new SymfonyStyle($input, $output),
Application::class => $this->command->getApplication(),
default => throw new RuntimeException(\sprintf('Unsupported type "%s" for parameter "$%s".', $type->getName(), $parameter->getName())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Completion\Suggestion;
use Symfony\Component\Console\Cursor;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Fixtures\InvokableTestCommand;

class InvokableCommandTest extends TestCase
Expand Down Expand Up @@ -462,6 +465,25 @@ public function testInvalidRequiredValueOptionEvenWithDefault()
$command->run(new ArrayInput(['--a' => null]), new NullOutput());
}

public function testHelpersInjection()
{
$command = new Command('foo');
$command->setApplication(new Application());
$command->setCode(function (
InputInterface $input,
OutputInterface $output,
Cursor $cursor,
SymfonyStyle $io,
Application $application,
): int {
$this->addToAssertionCount(1);

return 0;
});

$command->run(new ArrayInput([]), new NullOutput());
}

public function getSuggestedRoles(CompletionInput $input): array
{
return ['ROLE_ADMIN', 'ROLE_USER'];
Expand Down