From 64bbb42553c925ebf7177945d048c18675188584 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 22 Mar 2025 23:17:52 +0100 Subject: Fix CLI flag parsing (#7430) * Fix CLI flag parsing fix https://github.com/FreshRSS/FreshRSS/issues/7428 * Fix other places * Forgotten debugging --- tests/cli/CliOptionsParserTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/cli/CliOptionsParserTest.php b/tests/cli/CliOptionsParserTest.php index 7aa9cdac3..6a67fa761 100644 --- a/tests/cli/CliOptionsParserTest.php +++ b/tests/cli/CliOptionsParserTest.php @@ -15,6 +15,7 @@ final class CliOptionsOptionalTest extends CliOptionsParser { public string $optionalValue = ''; public bool $optionalValueWithDefault = false; public string $defaultInputAndOptionalValueWithDefault = ''; + public bool $flag = false; public function __construct() { $this->addOption('string', (new CliOption('string', 's'))->deprecatedAs('deprecated-string')); @@ -38,7 +39,7 @@ final class CliOptionsOptionalAndRequiredTest extends CliOptionsParser { public string $string = ''; public int $int = 0; public bool $bool = false; - public string $flag = ''; + public bool $flag = false; public function __construct() { $this->addRequiredOption('required', new CliOption('required')); @@ -160,6 +161,16 @@ class CliOptionsParserTest extends TestCase { self::assertSame('optional', $result->defaultInputAndOptionalValueWithDefault); } + public static function testOptionWithFlag(): void { + $result = self::runOptionalOptions('--flag'); + self::assertTrue($result->flag); + } + + public static function testOptionWithNoFlag(): void { + $result = self::runOptionalOptions(''); + self::assertFalse($result->flag); + } + public static function testRequiredOptionNotSetReturnsError(): void { $result = self::runOptionalAndRequiredOptions(''); self::assertSame(['required' => 'invalid input: required cannot be empty'], $result->errors); -- cgit v1.2.3