|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\Attributes\DataProvider; |
15 | 15 | use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Component\Console\Exception\InvalidOptionException; |
16 | 17 | use Symfony\Component\Console\Input\ArgvInput; |
17 | 18 | use Symfony\Component\Console\Input\InputArgument; |
18 | 19 | use Symfony\Component\Console\Input\InputDefinition; |
@@ -108,6 +109,12 @@ public static function provideOptions() |
108 | 109 | ['foo' => null], |
109 | 110 | '->parse() parses long options with optional value specified with no separator and no value as null', |
110 | 111 | ], |
| 112 | + [ |
| 113 | + ['cli.php', '--foo=a'], |
| 114 | + [(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))->setAllowedValues(['a', 'b'])], |
| 115 | + ['foo' => 'a'], |
| 116 | + '->parse() parses long options with allowed values', |
| 117 | + ], |
111 | 118 | [ |
112 | 119 | ['cli.php', '-f'], |
113 | 120 | [new InputOption('foo', 'f')], |
@@ -232,9 +239,9 @@ public static function provideNegatableOptions() |
232 | 239 | } |
233 | 240 |
|
234 | 241 | #[DataProvider('provideInvalidInput')] |
235 | | - public function testInvalidInput($argv, $definition, $expectedExceptionMessage) |
| 242 | + public function testInvalidInput($argv, $definition, $expectedExceptionMessage, $exceptionClass = \RuntimeException::class) |
236 | 243 | { |
237 | | - $this->expectException(\RuntimeException::class); |
| 244 | + $this->expectException($exceptionClass); |
238 | 245 | $this->expectExceptionMessage($expectedExceptionMessage); |
239 | 246 |
|
240 | 247 | (new ArgvInput($argv))->bind($definition); |
@@ -272,6 +279,12 @@ public static function provideInvalidInput(): array |
272 | 279 | new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]), |
273 | 280 | 'The "--foo" option does not accept a value.', |
274 | 281 | ], |
| 282 | + [ |
| 283 | + ['cli.php', '--foo=invalid'], |
| 284 | + new InputDefinition([(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))->setAllowedValues(['a', 'b'])]), |
| 285 | + 'The value "invalid" is not valid for the "foo" option. Supported values are "a", "b".', |
| 286 | + InvalidOptionException::class, |
| 287 | + ], |
275 | 288 | [ |
276 | 289 | ['cli.php', 'foo', 'bar'], |
277 | 290 | new InputDefinition(), |
|
0 commit comments