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;
|
break;
|
||||||
} else {
|
} else {
|
||||||
$this->addLongOption($option->getName(), true);
|
$this->addLongOption($option->getName(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,6 +220,10 @@ class ArgvInput extends Input
|
|||||||
$value = null;
|
$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 (null === $value && $option->acceptValue() && count($this->parsed)) {
|
||||||
// if option accepts an optional or mandatory argument
|
// if option accepts an optional or mandatory argument
|
||||||
// let's see if there is one provided
|
// 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');
|
$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 {
|
try {
|
||||||
$input = new ArgvInput(array('cli.php', 'foo', 'bar'));
|
$input = new ArgvInput(array('cli.php', 'foo', 'bar'));
|
||||||
$input->bind(new InputDefinition());
|
$input->bind(new InputDefinition());
|
||||||
|
Reference in New Issue
Block a user