ArgvInputTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Tests\Input;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Input\ArgvInput;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\InputDefinition;
  15. use Symfony\Component\Console\Input\InputOption;
  16. class ArgvInputTest extends TestCase
  17. {
  18. public function testConstructor()
  19. {
  20. $_SERVER['argv'] = ['cli.php', 'foo'];
  21. $input = new ArgvInput();
  22. $r = new \ReflectionObject($input);
  23. $p = $r->getProperty('tokens');
  24. $p->setAccessible(true);
  25. $this->assertEquals(['foo'], $p->getValue($input), '__construct() automatically get its input from the argv server variable');
  26. }
  27. public function testParseArguments()
  28. {
  29. $input = new ArgvInput(['cli.php', 'foo']);
  30. $input->bind(new InputDefinition([new InputArgument('name')]));
  31. $this->assertEquals(['name' => 'foo'], $input->getArguments(), '->parse() parses required arguments');
  32. $input->bind(new InputDefinition([new InputArgument('name')]));
  33. $this->assertEquals(['name' => 'foo'], $input->getArguments(), '->parse() is stateless');
  34. }
  35. /**
  36. * @dataProvider provideOptions
  37. */
  38. public function testParseOptions($input, $options, $expectedOptions, $message)
  39. {
  40. $input = new ArgvInput($input);
  41. $input->bind(new InputDefinition($options));
  42. $this->assertSame($expectedOptions, $input->getOptions(), $message);
  43. }
  44. public function provideOptions()
  45. {
  46. return [
  47. [
  48. ['cli.php', '--foo'],
  49. [new InputOption('foo')],
  50. ['foo' => true],
  51. '->parse() parses long options without a value',
  52. ],
  53. [
  54. ['cli.php', '--foo=bar'],
  55. [new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)],
  56. ['foo' => 'bar'],
  57. '->parse() parses long options with a required value (with a = separator)',
  58. ],
  59. [
  60. ['cli.php', '--foo', 'bar'],
  61. [new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)],
  62. ['foo' => 'bar'],
  63. '->parse() parses long options with a required value (with a space separator)',
  64. ],
  65. [
  66. ['cli.php', '--foo='],
  67. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)],
  68. ['foo' => ''],
  69. '->parse() parses long options with optional value which is empty (with a = separator) as empty string',
  70. ],
  71. [
  72. ['cli.php', '--foo=', 'bar'],
  73. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)],
  74. ['foo' => ''],
  75. '->parse() parses long options with optional value without value specified or an empty string (with a = separator) followed by an argument as empty string',
  76. ],
  77. [
  78. ['cli.php', 'bar', '--foo'],
  79. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)],
  80. ['foo' => null],
  81. '->parse() parses long options with optional value which is empty (with a = separator) preceded by an argument',
  82. ],
  83. [
  84. ['cli.php', '--foo', '', 'bar'],
  85. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)],
  86. ['foo' => ''],
  87. '->parse() parses long options with optional value which is empty as empty string even followed by an argument',
  88. ],
  89. [
  90. ['cli.php', '--foo'],
  91. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)],
  92. ['foo' => null],
  93. '->parse() parses long options with optional value specified with no separator and no value as null',
  94. ],
  95. [
  96. ['cli.php', '-f'],
  97. [new InputOption('foo', 'f')],
  98. ['foo' => true],
  99. '->parse() parses short options without a value',
  100. ],
  101. [
  102. ['cli.php', '-fbar'],
  103. [new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)],
  104. ['foo' => 'bar'],
  105. '->parse() parses short options with a required value (with no separator)',
  106. ],
  107. [
  108. ['cli.php', '-f', 'bar'],
  109. [new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)],
  110. ['foo' => 'bar'],
  111. '->parse() parses short options with a required value (with a space separator)',
  112. ],
  113. [
  114. ['cli.php', '-f', ''],
  115. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)],
  116. ['foo' => ''],
  117. '->parse() parses short options with an optional empty value',
  118. ],
  119. [
  120. ['cli.php', '-f', '', 'foo'],
  121. [new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)],
  122. ['foo' => ''],
  123. '->parse() parses short options with an optional empty value followed by an argument',
  124. ],
  125. [
  126. ['cli.php', '-f', '', '-b'],
  127. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b')],
  128. ['foo' => '', 'bar' => true],
  129. '->parse() parses short options with an optional empty value followed by an option',
  130. ],
  131. [
  132. ['cli.php', '-f', '-b', 'foo'],
  133. [new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b')],
  134. ['foo' => null, 'bar' => true],
  135. '->parse() parses short options with an optional value which is not present',
  136. ],
  137. [
  138. ['cli.php', '-fb'],
  139. [new InputOption('foo', 'f'), new InputOption('bar', 'b')],
  140. ['foo' => true, 'bar' => true],
  141. '->parse() parses short options when they are aggregated as a single one',
  142. ],
  143. [
  144. ['cli.php', '-fb', 'bar'],
  145. [new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_REQUIRED)],
  146. ['foo' => true, 'bar' => 'bar'],
  147. '->parse() parses short options when they are aggregated as a single one and the last one has a required value',
  148. ],
  149. [
  150. ['cli.php', '-fb', 'bar'],
  151. [new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)],
  152. ['foo' => true, 'bar' => 'bar'],
  153. '->parse() parses short options when they are aggregated as a single one and the last one has an optional value',
  154. ],
  155. [
  156. ['cli.php', '-fbbar'],
  157. [new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)],
  158. ['foo' => true, 'bar' => 'bar'],
  159. '->parse() parses short options when they are aggregated as a single one and the last one has an optional value with no separator',
  160. ],
  161. [
  162. ['cli.php', '-fbbar'],
  163. [new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)],
  164. ['foo' => 'bbar', 'bar' => null],
  165. '->parse() parses short options when they are aggregated as a single one and one of them takes a value',
  166. ],
  167. ];
  168. }
  169. /**
  170. * @dataProvider provideInvalidInput
  171. */
  172. public function testInvalidInput($argv, $definition, $expectedExceptionMessage)
  173. {
  174. if (method_exists($this, 'expectException')) {
  175. $this->expectException('RuntimeException');
  176. $this->expectExceptionMessage($expectedExceptionMessage);
  177. } else {
  178. $this->setExpectedException('RuntimeException', $expectedExceptionMessage);
  179. }
  180. $input = new ArgvInput($argv);
  181. $input->bind($definition);
  182. }
  183. public function provideInvalidInput()
  184. {
  185. return [
  186. [
  187. ['cli.php', '--foo'],
  188. new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)]),
  189. 'The "--foo" option requires a value.',
  190. ],
  191. [
  192. ['cli.php', '-f'],
  193. new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)]),
  194. 'The "--foo" option requires a value.',
  195. ],
  196. [
  197. ['cli.php', '-ffoo'],
  198. new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]),
  199. 'The "-o" option does not exist.',
  200. ],
  201. [
  202. ['cli.php', '--foo=bar'],
  203. new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]),
  204. 'The "--foo" option does not accept a value.',
  205. ],
  206. [
  207. ['cli.php', 'foo', 'bar'],
  208. new InputDefinition(),
  209. 'No arguments expected, got "foo".',
  210. ],
  211. [
  212. ['cli.php', 'foo', 'bar'],
  213. new InputDefinition([new InputArgument('number')]),
  214. 'Too many arguments, expected arguments "number".',
  215. ],
  216. [
  217. ['cli.php', 'foo', 'bar', 'zzz'],
  218. new InputDefinition([new InputArgument('number'), new InputArgument('county')]),
  219. 'Too many arguments, expected arguments "number" "county".',
  220. ],
  221. [
  222. ['cli.php', '--foo'],
  223. new InputDefinition(),
  224. 'The "--foo" option does not exist.',
  225. ],
  226. [
  227. ['cli.php', '-f'],
  228. new InputDefinition(),
  229. 'The "-f" option does not exist.',
  230. ],
  231. [
  232. ['cli.php', '-1'],
  233. new InputDefinition([new InputArgument('number')]),
  234. 'The "-1" option does not exist.',
  235. ],
  236. [
  237. ['cli.php', '-fЩ'],
  238. new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]),
  239. 'The "-Щ" option does not exist.',
  240. ],
  241. ];
  242. }
  243. public function testParseArrayArgument()
  244. {
  245. $input = new ArgvInput(['cli.php', 'foo', 'bar', 'baz', 'bat']);
  246. $input->bind(new InputDefinition([new InputArgument('name', InputArgument::IS_ARRAY)]));
  247. $this->assertEquals(['name' => ['foo', 'bar', 'baz', 'bat']], $input->getArguments(), '->parse() parses array arguments');
  248. }
  249. public function testParseArrayOption()
  250. {
  251. $input = new ArgvInput(['cli.php', '--name=foo', '--name=bar', '--name=baz']);
  252. $input->bind(new InputDefinition([new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)]));
  253. $this->assertEquals(['name' => ['foo', 'bar', 'baz']], $input->getOptions(), '->parse() parses array options ("--option=value" syntax)');
  254. $input = new ArgvInput(['cli.php', '--name', 'foo', '--name', 'bar', '--name', 'baz']);
  255. $input->bind(new InputDefinition([new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)]));
  256. $this->assertEquals(['name' => ['foo', 'bar', 'baz']], $input->getOptions(), '->parse() parses array options ("--option value" syntax)');
  257. $input = new ArgvInput(['cli.php', '--name=foo', '--name=bar', '--name=']);
  258. $input->bind(new InputDefinition([new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)]));
  259. $this->assertSame(['name' => ['foo', 'bar', '']], $input->getOptions(), '->parse() parses empty array options as null ("--option=value" syntax)');
  260. $input = new ArgvInput(['cli.php', '--name', 'foo', '--name', 'bar', '--name', '--anotherOption']);
  261. $input->bind(new InputDefinition([
  262. new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY),
  263. new InputOption('anotherOption', null, InputOption::VALUE_NONE),
  264. ]));
  265. $this->assertSame(['name' => ['foo', 'bar', null], 'anotherOption' => true], $input->getOptions(), '->parse() parses empty array options ("--option value" syntax)');
  266. }
  267. public function testParseNegativeNumberAfterDoubleDash()
  268. {
  269. $input = new ArgvInput(['cli.php', '--', '-1']);
  270. $input->bind(new InputDefinition([new InputArgument('number')]));
  271. $this->assertEquals(['number' => '-1'], $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
  272. $input = new ArgvInput(['cli.php', '-f', 'bar', '--', '-1']);
  273. $input->bind(new InputDefinition([new InputArgument('number'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)]));
  274. $this->assertEquals(['foo' => 'bar'], $input->getOptions(), '->parse() parses arguments with leading dashes as options before having encountered a double-dash sequence');
  275. $this->assertEquals(['number' => '-1'], $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
  276. }
  277. public function testParseEmptyStringArgument()
  278. {
  279. $input = new ArgvInput(['cli.php', '-f', 'bar', '']);
  280. $input->bind(new InputDefinition([new InputArgument('empty'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)]));
  281. $this->assertEquals(['empty' => ''], $input->getArguments(), '->parse() parses empty string arguments');
  282. }
  283. public function testGetFirstArgument()
  284. {
  285. $input = new ArgvInput(['cli.php', '-fbbar']);
  286. $this->assertNull($input->getFirstArgument(), '->getFirstArgument() returns null when there is no arguments');
  287. $input = new ArgvInput(['cli.php', '-fbbar', 'foo']);
  288. $this->assertEquals('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
  289. $input = new ArgvInput(['cli.php', '--foo', 'fooval', 'bar']);
  290. $input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('arg')]));
  291. $this->assertSame('bar', $input->getFirstArgument());
  292. $input = new ArgvInput(['cli.php', '-bf', 'fooval', 'argval']);
  293. $input->bind(new InputDefinition([new InputOption('bar', 'b', InputOption::VALUE_NONE), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('arg')]));
  294. $this->assertSame('argval', $input->getFirstArgument());
  295. }
  296. public function testHasParameterOption()
  297. {
  298. $input = new ArgvInput(['cli.php', '-f', 'foo']);
  299. $this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
  300. $input = new ArgvInput(['cli.php', '-etest']);
  301. $this->assertTrue($input->hasParameterOption('-e'), '->hasParameterOption() returns true if the given short option is in the raw input');
  302. $this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');
  303. $input = new ArgvInput(['cli.php', '--foo', 'foo']);
  304. $this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
  305. $input = new ArgvInput(['cli.php', 'foo']);
  306. $this->assertFalse($input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input');
  307. $input = new ArgvInput(['cli.php', '--foo=bar']);
  308. $this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given option with provided value is in the raw input');
  309. }
  310. public function testHasParameterOptionOnlyOptions()
  311. {
  312. $input = new ArgvInput(['cli.php', '-f', 'foo']);
  313. $this->assertTrue($input->hasParameterOption('-f', true), '->hasParameterOption() returns true if the given short option is in the raw input');
  314. $input = new ArgvInput(['cli.php', '--foo', '--', 'foo']);
  315. $this->assertTrue($input->hasParameterOption('--foo', true), '->hasParameterOption() returns true if the given long option is in the raw input');
  316. $input = new ArgvInput(['cli.php', '--foo=bar', 'foo']);
  317. $this->assertTrue($input->hasParameterOption('--foo', true), '->hasParameterOption() returns true if the given long option with provided value is in the raw input');
  318. $input = new ArgvInput(['cli.php', '--', '--foo']);
  319. $this->assertFalse($input->hasParameterOption('--foo', true), '->hasParameterOption() returns false if the given option is in the raw input but after an end of options signal');
  320. }
  321. public function testHasParameterOptionEdgeCasesAndLimitations()
  322. {
  323. $input = new ArgvInput(['cli.php', '-fh']);
  324. // hasParameterOption does not know if the previous short option, -f,
  325. // takes a value or not. If -f takes a value, then -fh does NOT include
  326. // -h; Otherwise it does. Since we do not know which short options take
  327. // values, hasParameterOption does not support this use-case.
  328. $this->assertFalse($input->hasParameterOption('-h'), '->hasParameterOption() returns true if the given short option is in the raw input');
  329. // hasParameterOption does detect that `-fh` contains `-f`, since
  330. // `-f` is the first short option in the set.
  331. $this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
  332. // The test below happens to pass, although it might make more sense
  333. // to disallow it, and require the use of
  334. // $input->hasParameterOption('-f') && $input->hasParameterOption('-h')
  335. // instead.
  336. $this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
  337. // In theory, if -fh is supported, then -hf should also work.
  338. // However, this is not supported.
  339. $this->assertFalse($input->hasParameterOption('-hf'), '->hasParameterOption() returns true if the given short option is in the raw input');
  340. $input = new ArgvInput(['cli.php', '-f', '-h']);
  341. // If hasParameterOption('-fh') is supported for 'cli.php -fh', then
  342. // one might also expect that it should also be supported for
  343. // 'cli.php -f -h'. However, this is not supported.
  344. $this->assertFalse($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
  345. }
  346. public function testNoWarningOnInvalidParameterOption()
  347. {
  348. $input = new ArgvInput(['cli.php', '-edev']);
  349. $this->assertTrue($input->hasParameterOption(['-e', '']));
  350. // No warning thrown
  351. $this->assertFalse($input->hasParameterOption(['-m', '']));
  352. $this->assertEquals('dev', $input->getParameterOption(['-e', '']));
  353. // No warning thrown
  354. $this->assertFalse($input->getParameterOption(['-m', '']));
  355. }
  356. public function testToString()
  357. {
  358. $input = new ArgvInput(['cli.php', '-f', 'foo']);
  359. $this->assertEquals('-f foo', (string) $input);
  360. $input = new ArgvInput(['cli.php', '-f', '--bar=foo', 'a b c d', "A\nB'C"]);
  361. $this->assertEquals('-f --bar=foo '.escapeshellarg('a b c d').' '.escapeshellarg("A\nB'C"), (string) $input);
  362. }
  363. /**
  364. * @dataProvider provideGetParameterOptionValues
  365. */
  366. public function testGetParameterOptionEqualSign($argv, $key, $default, $onlyParams, $expected)
  367. {
  368. $input = new ArgvInput($argv);
  369. $this->assertEquals($expected, $input->getParameterOption($key, $default, $onlyParams), '->getParameterOption() returns the expected value');
  370. }
  371. public function provideGetParameterOptionValues()
  372. {
  373. return [
  374. [['app/console', 'foo:bar'], '-e', 'default', false, 'default'],
  375. [['app/console', 'foo:bar', '-e', 'dev'], '-e', 'default', false, 'dev'],
  376. [['app/console', 'foo:bar', '--env=dev'], '--env', 'default', false, 'dev'],
  377. [['app/console', 'foo:bar', '-e', 'dev'], ['-e', '--env'], 'default', false, 'dev'],
  378. [['app/console', 'foo:bar', '--env=dev'], ['-e', '--env'], 'default', false, 'dev'],
  379. [['app/console', 'foo:bar', '--env=dev', '--en=1'], ['--en'], 'default', false, '1'],
  380. [['app/console', 'foo:bar', '--env=dev', '', '--en=1'], ['--en'], 'default', false, '1'],
  381. [['app/console', 'foo:bar', '--env', 'val'], '--env', 'default', false, 'val'],
  382. [['app/console', 'foo:bar', '--env', 'val', '--dummy'], '--env', 'default', false, 'val'],
  383. [['app/console', 'foo:bar', '--', '--env=dev'], '--env', 'default', false, 'dev'],
  384. [['app/console', 'foo:bar', '--', '--env=dev'], '--env', 'default', true, 'default'],
  385. ];
  386. }
  387. public function testParseSingleDashAsArgument()
  388. {
  389. $input = new ArgvInput(['cli.php', '-']);
  390. $input->bind(new InputDefinition([new InputArgument('file')]));
  391. $this->assertEquals(['file' => '-'], $input->getArguments(), '->parse() parses single dash as an argument');
  392. }
  393. public function testParseOptionWithValueOptionalGivenEmptyAndRequiredArgument()
  394. {
  395. $input = new ArgvInput(['cli.php', '--foo=', 'bar']);
  396. $input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)]));
  397. $this->assertEquals(['foo' => null], $input->getOptions(), '->parse() parses optional options with empty value as null');
  398. $this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses required arguments');
  399. $input = new ArgvInput(['cli.php', '--foo=0', 'bar']);
  400. $input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)]));
  401. $this->assertEquals(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
  402. $this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses required arguments');
  403. }
  404. public function testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument()
  405. {
  406. $input = new ArgvInput(['cli.php', '--foo=', 'bar']);
  407. $input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::OPTIONAL)]));
  408. $this->assertEquals(['foo' => null], $input->getOptions(), '->parse() parses optional options with empty value as null');
  409. $this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
  410. $input = new ArgvInput(['cli.php', '--foo=0', 'bar']);
  411. $input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::OPTIONAL)]));
  412. $this->assertEquals(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
  413. $this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
  414. }
  415. }