minor #19446 [Console] Overcomplete argument exception message tweak. (SpacePossum)

This PR was squashed before being merged into the 2.7 branch (closes #19446).

Discussion
----------

[Console] Overcomplete argument exception message tweak.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Updates the exception message when to many arguments are passed.
From;
```php
'Too many arguments.'
```
To:
```php
'No argument expected, got "foo".'
// or
'Too many arguments, expected arguments "foo".'
// or
'Too many arguments, expected arguments "foo, bar".'
// ... turtles all the way down
```

Commits
-------

7af59cd [Console] Overcomplete argument exception message tweak.
This commit is contained in:
Fabien Potencier 2016-07-28 13:56:28 -04:00
commit bdfc2aa652
2 changed files with 17 additions and 2 deletions

View File

@ -174,7 +174,12 @@ class ArgvInput extends Input
// unexpected argument
} else {
throw new \RuntimeException('Too many arguments.');
$all = $this->definition->getArguments();
if (count($all)) {
throw new \RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
}
throw new \RuntimeException(sprintf('No arguments expected, got "%s".', $token));
}
}

View File

@ -183,7 +183,17 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
array(
array('cli.php', 'foo', 'bar'),
new InputDefinition(),
'Too many arguments.',
'No arguments expected, got "foo".',
),
array(
array('cli.php', 'foo', 'bar'),
new InputDefinition(array(new InputArgument('number'))),
'Too many arguments, expected arguments "number".',
),
array(
array('cli.php', 'foo', 'bar', 'zzz'),
new InputDefinition(array(new InputArgument('number'), new InputArgument('county'))),
'Too many arguments, expected arguments "number" "county".',
),
array(
array('cli.php', '--foo'),