From 117b9007ad3899a9247abf42c50e3d96005d68f9 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 14 Oct 2023 10:55:55 +0200 Subject: [PATCH 1/3] Add test for failing input mode --- src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php index a47d557b78cd9..147497c586bfe 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php @@ -231,6 +231,12 @@ public static function provideNegatableOptions() ['foo' => false], '->parse() parses long options without a value', ], + [ + ['cli.php'], + [new InputOption('foo', null, InputOption::VALUE_NONE | InputOption::VALUE_NEGATABLE, '', false)], + ['foo' => false], + '->parse() parses long options without a value', + ], ]; } From 9dd142be06abd0898584a7a5cf14c9ab6374151f Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 14 Oct 2023 11:03:28 +0200 Subject: [PATCH 2/3] Allow default values for negatable input in InputOption --- src/Symfony/Component/Console/Input/InputOption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/InputOption.php b/src/Symfony/Component/Console/Input/InputOption.php index bb533801f123b..4d1777a6cbaa2 100644 --- a/src/Symfony/Component/Console/Input/InputOption.php +++ b/src/Symfony/Component/Console/Input/InputOption.php @@ -186,7 +186,7 @@ public function setDefault(string|bool|int|float|array|null $default = null) if (1 > \func_num_args()) { trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); } - if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) { + if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && !$this->isNegatable() && null !== $default) { throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.'); } From f4692c37a1d506678ed58ad342c318aef2d48981 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 14 Oct 2023 11:04:51 +0200 Subject: [PATCH 3/3] Add test to ensure default value is allowed with InputOption::VALUE_NEGATABLE --- src/Symfony/Component/Console/Tests/Input/InputOptionTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php b/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php index 7e3fb16da1fe9..6a87cbadfaf03 100644 --- a/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php +++ b/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php @@ -174,6 +174,10 @@ public function testSetDefault() $option = new InputOption('foo', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY); $option->setDefault([1, 2]); $this->assertEquals([1, 2], $option->getDefault(), '->setDefault() changes the default value'); + + $option = new InputOption('foo', null, InputOption::VALUE_NONE | InputOption::VALUE_NEGATABLE); + $option->setDefault(true); + $this->assertTrue($option->getDefault(), '->setDefault() changes the default value'); } public function testDefaultValueWithValueNoneMode()