@@ -71,6 +71,18 @@ public function provideOptions()
71
71
array ('foo ' => 'bar ' ),
72
72
'->parse() parses long options with a required value (with a space separator) ' ,
73
73
),
74
+ array (
75
+ array ('cli.php ' , '--foo= ' ),
76
+ array (new InputOption ('foo ' , 'f ' , InputOption::VALUE_OPTIONAL )),
77
+ array ('foo ' => null ),
78
+ '->parse() parses long options with optionnal value which is empty (with a = separator) as null ' ,
79
+ ),
80
+ array (
81
+ array ('cli.php ' , '--foo= ' , 'bar ' ),
82
+ array (new InputOption ('foo ' , 'f ' , InputOption::VALUE_OPTIONAL ), new InputArgument ('name ' , InputArgument::REQUIRED )),
83
+ array ('foo ' => null ),
84
+ '->parse() parses long options with optionnal value which is empty (with a = separator) followed by an argument ' ,
85
+ ),
74
86
array (
75
87
array ('cli.php ' , '-f ' ),
76
88
array (new InputOption ('foo ' , 'f ' )),
@@ -324,4 +336,30 @@ public function testParseSingleDashAsArgument()
324
336
$ input ->bind (new InputDefinition (array (new InputArgument ('file ' ))));
325
337
$ this ->assertEquals (array ('file ' => '- ' ), $ input ->getArguments (), '->parse() parses single dash as an argument ' );
326
338
}
339
+
340
+ public function testParseOptionWithValueOptionalGivenEmptyAndRequiredArgument ()
341
+ {
342
+ $ input = new ArgvInput (array ('cli.php ' , '--foo= ' , 'bar ' ));
343
+ $ input ->bind (new InputDefinition (array (new InputOption ('foo ' , 'f ' , InputOption::VALUE_OPTIONAL ), new InputArgument ('name ' , InputArgument::REQUIRED ))));
344
+ $ this ->assertEquals (array ('foo ' => null ), $ input ->getOptions (), '->parse() parses optional options with empty value as null ' );
345
+ $ this ->assertEquals (array ('name ' => 'bar ' ), $ input ->getArguments (), '->parse() parses required arguments ' );
346
+
347
+ $ input = new ArgvInput (array ('cli.php ' , '--foo=0 ' , 'bar ' ));
348
+ $ input ->bind (new InputDefinition (array (new InputOption ('foo ' , 'f ' , InputOption::VALUE_OPTIONAL ), new InputArgument ('name ' , InputArgument::REQUIRED ))));
349
+ $ this ->assertEquals (array ('foo ' => '0 ' ), $ input ->getOptions (), '->parse() parses optional options with empty value as null ' );
350
+ $ this ->assertEquals (array ('name ' => 'bar ' ), $ input ->getArguments (), '->parse() parses required arguments ' );
351
+ }
352
+
353
+ public function testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument ()
354
+ {
355
+ $ input = new ArgvInput (array ('cli.php ' , '--foo= ' , 'bar ' ));
356
+ $ input ->bind (new InputDefinition (array (new InputOption ('foo ' , 'f ' , InputOption::VALUE_OPTIONAL ), new InputArgument ('name ' , InputArgument::OPTIONAL ))));
357
+ $ this ->assertEquals (array ('foo ' => null ), $ input ->getOptions (), '->parse() parses optional options with empty value as null ' );
358
+ $ this ->assertEquals (array ('name ' => 'bar ' ), $ input ->getArguments (), '->parse() parses required arguments ' );
359
+
360
+ $ input = new ArgvInput (array ('cli.php ' , '--foo=0 ' , 'bar ' ));
361
+ $ input ->bind (new InputDefinition (array (new InputOption ('foo ' , 'f ' , InputOption::VALUE_OPTIONAL ), new InputArgument ('name ' , InputArgument::OPTIONAL ))));
362
+ $ this ->assertEquals (array ('foo ' => '0 ' ), $ input ->getOptions (), '->parse() parses optional options with empty value as null ' );
363
+ $ this ->assertEquals (array ('name ' => 'bar ' ), $ input ->getArguments (), '->parse() parses required arguments ' );
364
+ }
327
365
}
0 commit comments