10000 merged branch lyrixx/console-typo (PR #5208) · symfony/symfony@268b618 · GitHub
[go: up one dir, main page]

Skip to content

Commit 268b618

Browse files
committed
merged branch lyrixx/console-typo (PR #5208)
Commits ------- 039264d [Console] Fixed tests about message exception when command is not available a4d2d31 [Console] Added tests for message exception when command is not available Discussion ---------- [Console] Fixed message exception when command is not avaible Bug fix: yes Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - License of the code: MIT Fixed singular / plural `Did you mean this?` VS `Did you mean one of these` --------------------------------------------------------------------------- by travisbot at 2012-08-07T14:40:55Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/2057647) (merged 039264d into b91a4a8). --------------------------------------------------------------------------- by lyrixx at 2012-08-07T15:11:47Z @travisbot You failed, not me !
2 parents 1122be7 + 039264d commit 268b618

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,12 @@ public function findNamespace($namespace)
496496
}
497497

498498
if ($alternatives = $this->findAlternativeNamespace($part, $abbrevs)) {
499-
$message .= "\n\nDid you mean one of these?\n ";
499+
if (1 == count($alternatives)) {
500+
$message .= "\n\nDid you mean this?\n ";
501+
} else {
502+
$message .= "\n\nDid you mean one of these?\n ";
503+
}
504+
500505
$message .= implode("\n ", $alternatives);
501506
}
502507

@@ -571,7 +576,11 @@ public function find($name)
571576
$message = sprintf('Command "%s" is not defined.', $name);
572577

573578
if ($alternatives = $this->findAlternativeCommands($searchName, $abbrevs)) {
574-
$message .= "\n\nDid you mean one of these?\n ";
579+
if (1 == count($alternatives)) {
580+
$message .= "\n\nDid you mean this?\n ";
581+
} else {
582+
$message .= "\n\nDid you mean one of these?\n ";
583+
}
575584
$message .= implode("\n ", $alternatives);
576585
}
577586

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,52 @@ public function testFind()
215215
}
216216
}
217217

218+
public function testFindAlternativeExceptionMessage()
219+
{
220+
$application = new Application();
221+
$application->add(new \FooCommand());
222+
223+
// Command + singular
224+
try {
225+
$application->find('foo:baR');
226+
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
227+
} catch (\Exception $e) {
228+
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
229+
$this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
230+
}
231+
232+
// Namespace + singular
233+
try {
234+
$application->find('foO:bar');
235+
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
236+
} catch (\Exception $e) {
237+
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
238+
$this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
239+
}
240+
241+
242+
$application->add(new \Foo1Command());
243+
$application->add(new \Foo2Command());
244+
245+
// Command + plural
246+
try {
247+
$application->find('foo:baR');
248+
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
249+
} catch (\Exception $e) {
250+
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
251+
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
252+
}
253+
254+
// Namespace + plural
255+
try {
256+
$application->find('foo2:bar');
257+
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
258+
} catch (\Exception $e) {
259+
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
260+
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
261+
}
262+
}
263+
218264
public function testFindAlternativeCommands()
219265
{
220266
$application = new Application();

0 commit comments

Comments
 (0)
0