8000 [Console] Expose the original input arguments and options and to unparse options by theofidry · Pull Request #57598 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Expose the original input arguments and options and to unparse options #57598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
doc
  • Loading branch information
theofidry committed Apr 18, 2025
commit d36058e429ca518dc5175d22de3bc550c6c8582e
1 change: 0 additions & 1 deletion src/Symfony/Component/Console/Console

This file was deleted.

4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Input/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public function getStream()
/**
* Returns a stringified representation of the options passed to the command.
*
* InputArguments MUST be escaped as well as the InputOption values passed to the command.
* InputArguments must NOT be escaped as otherwise passing them to a `Process` would result in them being escaped twice.
*
* @param string[] $optionNames Name of the options returned. If empty, all options are returned and non-passed or non-existent are ignored.
* @param string[] $optionNames Names of the options returned. If empty, all options are returned and non-passed or non-existent are ignored.
*
* @return list<string>
*/
Expand Down
28 changes: 14 additions & 14 deletions src/Symfony/Component/Console/Tests/Input/InputTest.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ class InputTest extends TestCase
public function testConstructor()
{
$input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name')]));
$this->assertEquals('foo', $input->getArgument('name'), '->__construct() takes a InputDefinition as an argument');
$this->assertSame('foo', $input->getArgument('name'), '->__construct() takes a InputDefinition as an argument');
}

public function testOptions()
{
$input = new ArrayInput(['--name' => 'foo'], new InputDefinition([new InputOption('name')]));
$this->assertEquals('foo', $input->getOption('name'), '->getOption() returns the value for the given option');
$this->assertSame('foo', $input->getOption('name'), '->getOption() returns the value for the given option');

$input->setOption('name', 'bar');
$this->assertEquals('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
$this->assertEquals(['name' => 'bar'], $input->getOptions(), '->getOptions() returns all option values');
$this->assertSame('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
$this->assertSame(['name' => 'bar'], $input->getOptions(), '->getOptions() returns all option values');

$input = new ArrayInput(['--name' => 'foo'], new InputDefinition([new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')]));
$this->assertEquals('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
$this->assertEquals(['name' => 'foo', 'bar' => 'default'], $input->getOptions(), '->getOptions() returns all option values, even optional ones');
$this->assertSame('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
$this->assertSame(['name' => 'foo', 'bar' => 'default'], $input->getOptions(), '->getOptions() returns all option values, even optional ones');

$input = new ArrayInput(['--name' => 'foo', '--bar' => ''], new InputDefinition([new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')]));
$this->assertEquals('', $input->getOption('bar'), '->getOption() returns null for options explicitly passed without value (or an empty value)');
$this->assertEquals(['name' => 'foo', 'bar' => ''], $input->getOptions(), '->getOptions() returns all option values.');
$this->assertSame('', $input->getOption('bar'), '->getOption() returns null for options explicitly passed without value (or an empty value)');
$this->assertSame(['name' => 'foo', 'bar' => ''], $input->getOptions(), '->getOptions() returns all option values.');

$input = new ArrayInput(['--name' => 'foo', '--bar' => null], new InputDefinition([new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')]));
$this->assertNull($input->getOption('bar'), '->getOption() returns null for options explicitly passed without value (or an empty value)');
$this->assertEquals(['name' => 'foo', 'bar' => null], $input->getOptions(), '->getOptions() returns all option values');
$this->assertSame(['name' => 'foo', 'bar' => null], $input->getOptions(), '->getOptions() returns all option values');
$this->assertSame(['name' => 'foo', 'bar' => null], $input->getRawOptions(), '->getRawOptions() returns all option values');

$input = new ArrayInput(['--name' => null], new InputDefinition([new InputOption('name', null, InputOption::VALUE_NEGATABLE)]));
Expand Down Expand Up @@ -85,16 +85,16 @@ public function testGetInvalidOption()
public function testArguments()
{
$input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name')]));
$this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
$this->assertSame('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');

$input->setArgument('name', 'bar');
$this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->getArguments() returns all argument values');
$this->assertSame('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
$this->assertSame(['name' => 'bar'], $input->getArguments(), '->getArguments() returns all argument values');
$this->assertSame(['name' => 'bar'], $input->getRawArguments(), '->getRawArguments() returns all argument values');

$input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')]));
$this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
$this->assertEquals(['name' => 'foo', 'bar' => 'default'], $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
$this->assertSame('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
$this->assertSame(['name' => 'foo', 'bar' => 'default'], $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
$this->assertSame(['name' => 'foo'], $input->getRawArguments(), '->getRawArguments() returns all argument values, excluding optional ones');
}

Expand Down
0