Skip to content

Commit

Permalink
Merge branch '4.4' into 5.4
Browse files Browse the repository at this point in the history
* 4.4:
  [Console] Better required argument check in InputArgument
  [EventDispatcher] Fix removing listeners when using first-class callable syntax
  • Loading branch information
nicolas-grekas committed May 5, 2022
2 parents ffe3aed + 3aac1c4 commit 4f43a3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Input/InputArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function isArray()
*/
public function setDefault($default = null)
{
if (self::REQUIRED === $this->mode && null !== $default) {
if ($this->isRequired() && null !== $default) {
throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/Input/InputArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public function testSetDefaultWithRequiredArgument()
$argument->setDefault('default');
}

public function testSetDefaultWithRequiredArrayArgument()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot set a default value except for InputArgument::OPTIONAL mode.');
$argument = new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY);
$argument->setDefault([]);
}

public function testSetDefaultWithArrayArgument()
{
$this->expectException(\LogicException::class);
Expand Down

0 comments on commit 4f43a3f

Please sign in to comment.