$input = new ArgvInput($input);
$input->bind(new InputDefinition($options));
- $this->assertEquals($expectedOptions, $input->getOptions(), $message);
+ $this->assertSame($expectedOptions, $input->getOptions(), $message);
}
public function provideOptions()
array(
array('cli.php', '--foo='),
array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)),
- array('foo' => null),
- '->parse() parses long options with optional value which is empty (with a = separator) as null',
+ array('foo' => ''),
+ '->parse() parses long options with optional value which is empty (with a = separator) as empty string',
),
array(
array('cli.php', '--foo=', 'bar'),
array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)),
+ array('foo' => ''),
+ '->parse() parses long options with optional value without value specified or an empty string (with a = separator) followed by an argument as empty string',
+ ),
+ array(
+ array('cli.php', 'bar', '--foo'),
+ array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)),
array('foo' => null),
- '->parse() parses long options with optional value which is empty (with a = separator) followed by an argument',
+ '->parse() parses long options with optional value which is empty (with a = separator) preceded by an argument',
+ ),
+ array(
+ array('cli.php', '--foo', '', 'bar'),
+ array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)),
+ array('foo' => ''),
+ '->parse() parses long options with optional value which is empty as empty string even followed by an argument',
+ ),
+ array(
+ array('cli.php', '--foo'),
+ array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)),
+ array('foo' => null),
+ '->parse() parses long options with optional value specified with no separator and no value as null',
),
array(
array('cli.php', '-f'),
$input = new ArgvInput(array('cli.php', '--name=foo', '--name=bar', '--name='));
$input->bind(new InputDefinition(array(new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY))));
- $this->assertSame(array('name' => array('foo', 'bar', null)), $input->getOptions(), '->parse() parses empty array options as null ("--option=value" syntax)');
+ $this->assertSame(array('name' => array('foo', 'bar', '')), $input->getOptions(), '->parse() parses empty array options as null ("--option=value" syntax)');
$input = new ArgvInput(array('cli.php', '--name', 'foo', '--name', 'bar', '--name', '--anotherOption'));
$input->bind(new InputDefinition(array(
new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY),
new InputOption('anotherOption', null, InputOption::VALUE_NONE),
)));
- $this->assertSame(array('name' => array('foo', 'bar', null), 'anotherOption' => true), $input->getOptions(), '->parse() parses empty array options as null ("--option value" syntax)');
+ $this->assertSame(array('name' => array('foo', 'bar', null), 'anotherOption' => true), $input->getOptions(), '->parse() parses empty array options ("--option value" syntax)');
}
public function testParseNegativeNumberAfterDoubleDash()
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
+ $input = new ArgvInput(array('cli.php', '-etest'));
+ $this->assertTrue($input->hasParameterOption('-e'), '->hasParameterOption() returns true if the given short option is in the raw input');
+ $this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');
+
$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
$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');
}
+ public function testHasParameterOptionEdgeCasesAndLimitations()
+ {
+ $input = new ArgvInput(array('cli.php', '-fh'));
+ // hasParameterOption does not know if the previous short option, -f,
+ // takes a value or not. If -f takes a value, then -fh does NOT include
+ // -h; Otherwise it does. Since we do not know which short options take
+ // values, hasParameterOption does not support this use-case.
+ $this->assertFalse($input->hasParameterOption('-h'), '->hasParameterOption() returns true if the given short option is in the raw input');
+ // hasParameterOption does detect that `-fh` contains `-f`, since
+ // `-f` is the first short option in the set.
+ $this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
+ // The test below happens to pass, although it might make more sense
+ // to disallow it, and require the use of
+ // $input->hasParameterOption('-f') && $input->hasParameterOption('-h')
+ // instead.
+ $this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
+ // In theory, if -fh is supported, then -hf should also work.
+ // However, this is not supported.
+ $this->assertFalse($input->hasParameterOption('-hf'), '->hasParameterOption() returns true if the given short option is in the raw input');
+
+ $input = new ArgvInput(array('cli.php', '-f', '-h'));
+ // If hasParameterOption('-fh') is supported for 'cli.php -fh', then
+ // one might also expect that it should also be supported for
+ // 'cli.php -f -h'. However, this is not supported.
+ $this->assertFalse($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
+ }
+
+ public function testNoWarningOnInvalidParameterOption()
+ {
+ $input = new ArgvInput(array('cli.php', '-edev'));
+
+ $this->assertTrue($input->hasParameterOption(array('-e', '')));
+ // No warning thrown
+ $this->assertFalse($input->hasParameterOption(array('-m', '')));
+
+ $this->assertEquals('dev', $input->getParameterOption(array('-e', '')));
+ // No warning thrown
+ $this->assertFalse($input->getParameterOption(array('-m', '')));
+ }
+
public function testToString()
{
$input = new ArgvInput(array('cli.php', '-f', 'foo'));