8000 minor #19446 [Console] Overcomplete argument exception message tweak.… · symfony/symfony@bdfc2aa · GitHub
[go: up one dir, main page]

Skip to content

Commit bdfc2aa

Browse files
committed
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.
2 parents 382ad65 + 7af59cd commit bdfc2aa

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ private function parseArgument($token)
174174

175175
// unexpected argument
176176
} else {
177-
throw new \RuntimeException('Too many arguments.');
177+
$all = $this->definition->getArguments();
178+
if (count($all)) {
179+
throw new \RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
180+
}
181+
182+
throw new \RuntimeException(sprintf('No arguments expected, got "%s".', $token));
178183
}
179184
}
180185

src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,17 @@ public function provideInvalidInput()
183183
array(
184184
array('cli.php', 'foo', 'bar'),
185185
new InputDefinition(),
186-
'Too many arguments.',
186+
'No arguments expected, got "foo".',
187+
),
188+
array(
189+
array('cli.php', 'foo', 'bar'),
190+
new InputDefinition(array(new InputArgument('number'))),
191+
'Too many arguments, expected arguments "number".',
192+
),
193+
array(
194+
array('cli.php', 'foo', 'bar', 'zzz'),
195+
new InputDefinition(array(new InputArgument('number'), new InputArgument('county'))),
196+
'Too many arguments, expected arguments "number" "county".',
187197
),
188198
array(
189199
array('cli.php', '--foo'),

0 commit comments

Comments
 (0)
0