@@ -296,6 +296,10 @@ public function testHasParameterOption()
296296 $ input = new ArgvInput (array ('cli.php ' , '-f ' , 'foo ' ));
297297 $ this ->assertTrue ($ input ->hasParameterOption ('-f ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
298298
299+ $ input = new ArgvInput (array ('cli.php ' , '-etest ' ));
300+ $ this ->assertTrue ($ input ->hasParameterOption ('-e ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
301+ $ this ->assertFalse ($ input ->hasParameterOption ('-s ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
302+
299303 $ input = new ArgvInput (array ('cli.php ' , '--foo ' , 'foo ' ));
300304 $ this ->assertTrue ($ input ->hasParameterOption ('--foo ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
301305
@@ -306,6 +310,33 @@ public function testHasParameterOption()
306310 $ this ->assertTrue ($ input ->hasParameterOption ('--foo ' ), '->hasParameterOption() returns true if the given option with provided value is in the raw input ' );
307311 }
308312
313+ public function testHasParameterOptionEdgeCasesAndLimitations ()
314+ {
315+ $ input = new ArgvInput (array ('cli.php ' , '-fh ' ));
316+ // hasParameterOption does not know if the previous short option, -f,
317+ // takes a value or not. If -f takes a value, then -fh does NOT include
318+ // -h; Otherwise it does. Since we do not know which short options take
319+ // values, hasParameterOption does not support this use-case.
320+ $ this ->assertFalse ($ input ->hasParameterOption ('-h ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
321+ // hasParameterOption does detect that `-fh` contains `-f`, since
322+ // `-f` is the first short option in the set.
323+ $ this ->assertTrue ($ input ->hasParameterOption ('-f ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
324+ // The test below happens to pass, although it might make more sense
325+ // to disallow it, and require the use of
326+ // $input->hasParameterOption('-f') && $input->hasParameterOption('-h')
327+ // instead.
328+ $ this ->assertTrue ($ input ->hasParameterOption ('-fh ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
329+ // In theory, if -fh is supported, then -hf should also work.
330+ // However, this is not supported.
331+ $ this ->assertFalse ($ input ->hasParameterOption ('-hf ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
332+
333+ $ input = new ArgvInput (array ('cli.php ' , '-f ' , '-h ' ));
334+ // If hasParameterOption('-fh') is supported for 'cli.php -fh', then
335+ // one might also expect that it should also be supported for
336+ // 'cli.php -f -h'. However, this is not supported.
337+ $ this ->assertFalse ($ input ->hasParameterOption ('-fh ' ), '->hasParameterOption() returns true if the given short option is in the raw input ' );
338+ }
339+
309340 public function testToString ()
310341 {
311342 $ input = new ArgvInput (array ('cli.php ' , '-f ' , 'foo ' ));
@@ -327,6 +358,7 @@ public function testGetParameterOptionEqualSign($argv, $key, $expected)
327358 public function provideGetParameterOptionValues ()
328359 {
329360 return array (
361+ array (array ('app/console ' , 'foo:bar ' , '-edev ' ), '-e ' , 'dev ' ),
330362 array (array ('app/console ' , 'foo:bar ' , '-e ' , 'dev ' ), '-e ' , 'dev ' ),
331363 array (array ('app/console ' , 'foo:bar ' , '--env=dev ' ), '--env ' , 'dev ' ),
332364 array (array ('app/console ' , 'foo:bar ' , '-e ' , 'dev ' ), array ('-e ' , '--env ' ), 'dev ' ),
0 commit comments