From 37774e6b72ae84ba05e8e5e55b31cc363da46acc Mon Sep 17 00:00:00 2001 From: Jaymin G <40832979+jayminsilicon@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:26:55 +0530 Subject: [PATCH] [Console] Allow false as a $shortcut in InputOption --- Input/InputOption.php | 2 +- Tests/Input/InputOptionTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Input/InputOption.php b/Input/InputOption.php index 1d8dbca31..99807f59e 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -69,7 +69,7 @@ public function __construct(string $name, $shortcut = null, ?int $mode = null, s throw new InvalidArgumentException('An option name cannot be empty.'); } - if ('' === $shortcut || [] === $shortcut) { + if ('' === $shortcut || [] === $shortcut || false === $shortcut) { $shortcut = null; } diff --git a/Tests/Input/InputOptionTest.php b/Tests/Input/InputOptionTest.php index 55a840ac7..83b295fcc 100644 --- a/Tests/Input/InputOptionTest.php +++ b/Tests/Input/InputOptionTest.php @@ -69,6 +69,8 @@ public function testShortcut() $this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in an array'); $option = new InputOption('foo', '0|z'); $this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in a string-list'); + $option = new InputOption('foo', false); + $this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given a false as value'); } public function testModes()