Skip to content

Commit

Permalink
Allow passing key/value arrays to getArguments and getOptions on Arti…
Browse files Browse the repository at this point in the history
…san commands (#42268)
  • Loading branch information
jnoordsij authored May 5, 2022
1 parent 3ec1e4c commit 57f7431
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 57f7431

Please sign in to comment.