diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 0f9b62c53f..6c3267c9fd 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -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 diff --git a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php index 472a91580c..532841c0b0 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php @@ -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());