8000 [Console] Better required argument check in InputArgument · symfony/symfony@89dd2bb · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 89dd2bb

Browse files
jnoordsijnicolas-grekas
authored andcommitted
[Console] Better required argument check in InputArgument
1 parent ce4a1a9 commit 89dd2bb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/Console/Input/InputArgument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function isArray()
9292
*/
9393
public function setDefault($default = null)
9494
{
95-
if (self::REQUIRED === $this->mode && null !== $default) {
95+
if ($this->isRequired() && null !== $default) {
9696
throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
9797
}
9898

src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ public function testSetDefaultWithRequiredArgument()
8888
$argument->setDefault('default');
8989
}
9090

91+
public function testSetDefaultWithRequiredArrayArgument()
92+
{
93+
$this->expectException(\LogicException::class);
94+
$this->expectExceptionMessage('Cannot set a default value except for InputArgument::OPTIONAL mode.');
95+
$argument = new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY);
96+
$argument->setDefault([]);
97+
}
98+
9199
public function testSetDefaultWithArrayArgument()
92100
{
93101
$this->expectException(\LogicException::class);

0 commit comments

Comments
 (0)
0