Throw exception if value is passed to VALUE_NONE input, long syntax
This commit is contained in:
parent
fb0a0a708b
commit
bcbbb28f76
|
@ -134,7 +134,7 @@ class ArgvInput extends Input
|
|||
|
||||
break;
|
||||
} else {
|
||||
$this->addLongOption($option->getName(), true);
|
||||
$this->addLongOption($option->getName(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +220,10 @@ class ArgvInput extends Input
|
|||
$value = null;
|
||||
}
|
||||
|
||||
if (null !== $value && !$option->acceptValue()) {
|
||||
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value));
|
||||
}
|
||||
|
||||
if (null === $value && $option->acceptValue() && count($this->parsed)) {
|
||||
// if option accepts an optional or mandatory argument
|
||||
// let's see if there is one provided
|
||||
|
|
|
@ -105,6 +105,15 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '--foo=bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))));
|
||||
$this->fail('->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
$this->assertEquals('The "--foo" option does not accept a value.', $e->getMessage(), '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', 'foo', 'bar'));
|
||||
$input->bind(new InputDefinition());
|
||||
|
|
Reference in New Issue