From 89dd2bb2495c67a71a77a88b358f67f9fb9bb7f4 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Thu, 5 May 2022 14:54:11 +0200 Subject: [PATCH] [Console] Better required argument check in InputArgument --- src/Symfony/Component/Console/Input/InputArgument.php | 2 +- .../Component/Console/Tests/Input/InputArgumentTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/InputArgument.php b/src/Symfony/Component/Console/Input/InputArgument.php index 085aca5a7443e..accd4d0c5b4d7 100644 --- a/src/Symfony/Component/Console/Input/InputArgument.php +++ b/src/Symfony/Component/Console/Input/InputArgument.php @@ -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.'); } diff --git a/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php b/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php index 4e583888a6b86..9dae4e2cace7e 100644 --- a/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php +++ b/src/Symfony/Component/Console/Tests/Input/InputArgumentTest.php @@ -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); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy