Skip to content
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

[9.x] Allow passing key/value arrays to getArguments and getOptions #42268

Merged
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
4 changes: 2 additions & 2 deletions src/Illuminate/Console/Concerns/HasParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ protected function specifyParameters()
if ($arguments instanceof InputArgument) {
$this->getDefinition()->addArgument($arguments);
} else {
$this->addArgument(...array_values($arguments));
$this->addArgument(...$arguments);
}
}

foreach ($this->getOptions() as $options) {
if ($options instanceof InputOption) {
$this->getDefinition()->addOption($options);
} else {
$this->addOption(...array_values($options));
$this->addOption(...$options);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Console/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ protected function getArguments()
return [
new InputArgument('argument-one', InputArgument::REQUIRED, 'first test argument'),
['argument-two', InputArgument::OPTIONAL, 'a second test argument'],
[
'name' => 'argument-three',
'description' => 'a third test argument',
'mode' => InputArgument::OPTIONAL,
'default' => 'third-argument-default',
],
];
}

Expand All @@ -73,6 +79,12 @@ protected function getOptions()
return [
new InputOption('option-one', 'o', InputOption::VALUE_OPTIONAL, 'first test option'),
['option-two', 't', InputOption::VALUE_REQUIRED, 'second test option'],
[
'name' => 'option-three',
'description' => 'a third test option',
'mode' => InputOption::VALUE_OPTIONAL,
'default' => 'third-option-default',
],
];
}
};
Expand All @@ -92,8 +104,10 @@ protected function getOptions()

$this->assertSame('test-first-argument', $command->argument('argument-one'));
$this->assertSame('test-second-argument', $command->argument('argument-two'));
$this->assertSame('third-argument-default', $command->argument('argument-three'));
$this->assertSame('test-first-option', $command->option('option-one'));
$this->assertSame('test-second-option', $command->option('option-two'));
$this->assertSame('third-option-default', $command->option('option-three'));
}

public function testTheInputSetterOverwrite()
Expand Down