Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cfe06ba

Browse filesBrowse files
committed
[Console] Invokable Command InputOption::VALUE_OPTIONAL
1 parent 05d5bb3 commit cfe06ba
Copy full SHA for cfe06ba

File tree

1 file changed

+22
-0
lines changed
Filter options

1 file changed

+22
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php
+22Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.