8000 [Console] Invokable Command `InputOption::VALUE_OPTIONAL` · symfony/symfony@cfe06ba · GitHub
[go: up one dir, main page]

Skip to content

Commit cfe06ba

Browse files
committed
[Console] Invokable Command InputOption::VALUE_OPTIONAL
1 parent 05d5bb3 commit cfe06ba

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,28 @@ public static function provideNonBinaryInputOptions(): \Generator
218218
yield 'without-value' => [['--a' => null, '--b' => null, '--c' => null], [null, null, null]];
219219
}
220220

221+
/**
222+
* @dataProvider provideOptionalInputOptions
223+
*/
224+
public function testOptionalValueOption(array $parameters, string|bool $expected)
225+
{
226+
$command = new Command('foo');
227+
$command->setCode(function (
228+
#[Option] string|bool $a = false,
229+
) use ($expected) {
230+
$this->assertSame($expected, $a);
231+
});
232+
233+
$command->run(new ArrayInput($parameters), new NullOutput());
234+
}
235+
236+
public static function provideOptionalInputOptions(): \Generator
237+
{
238+
yield 'default' => [[], false];
239+
yield 'with-value' => [['--a' => 'x'], 'x'];
240+
yield 'without-value' => [['--a' => null], true];
241+
}
242+
221243
public function testInvalidOptionDefinition()
222244
{
223245
$command = new Command('foo');

0 commit comments

Comments
 (0)
0