Skip to content

Navigation Menu

Sign in
Appearance settings

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 b287c25

Browse filesBrowse files
committed
Added tests and fixed one failing case
1 parent e263d0b commit b287c25
Copy full SHA for b287c25

File tree

2 files changed

+15
-1
lines changed
Filter options

2 files changed

+15
-1
lines changed

‎src/Symfony/Component/Console/Input/InputOption.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/InputOption.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct(string $name, $shortcut = null, int $mode = null, st
8181
$shortcuts = array_filter($shortcuts, 'strlen');
8282
$shortcut = implode('|', $shortcuts);
8383

84-
if (empty($shortcut)) {
84+
if ($shortcut === '') {
8585
throw new InvalidArgumentException('An option shortcut cannot be empty.');
8686
}
8787
}

‎src/Symfony/Component/Console/Tests/Input/InputOptionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Input/InputOptionTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public function testShortcut()
5555
$this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts');
5656
$option = new InputOption('foo');
5757
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
58+
$option = new InputOption('foo', '');
59+
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty string');
60+
$option = new InputOption('foo', []);
61+
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty array');
62+
$option = new InputOption('foo', ['f', '', 'fff']);
63+
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
64+
$option = new InputOption('foo', 'f||fff');
65+
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
66+
$option = new InputOption('foo', '0');
67+
$this->assertEquals('0', $option->getShortcut(), '-0 is an acceptable shortcut value');
68+
$option = new InputOption('foo', ['0', 'z']);
69+
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in an array');
70+
$option = new InputOption('foo', '0|z');
71+
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in a string-list');
5872
}
5973

6074
public function testModes()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.