Skip to content

Commit

Permalink
merged branch lyrixx/console-typo (PR #5208)
Browse files Browse the repository at this point in the history
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 !
  • Loading branch information
fabpot committed Aug 10, 2012
2 parents 1122be7 + 039264d commit 268b618
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,12 @@ public function findNamespace($namespace)
}

if ($alternatives = $this->findAlternativeNamespace($part, $abbrevs)) {
$message .= "\n\nDid you mean one of these?\n ";
if (1 == count($alternatives)) {
$message .= "\n\nDid you mean this?\n ";
} else {
$message .= "\n\nDid you mean one of these?\n ";
}

$message .= implode("\n ", $alternatives);
}

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

if ($alternatives = $this->findAlternativeCommands($searchName, $abbrevs)) {
$message .= "\n\nDid you mean one of these?\n ";
if (1 == count($alternatives)) {
$message .= "\n\nDid you mean this?\n ";
} else {
$message .= "\n\nDid you mean one of these?\n ";
}
$message .= implode("\n ", $alternatives);
}

Expand Down
46 changes: 46 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,52 @@ public function testFind()
}
}

public function testFindAlternativeExceptionMessage()
{
$application = new Application();
$application->add(new \FooCommand());

// Command + singular
try {
$application->find('foo:baR');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
$this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
}

// Namespace + singular
try {
$application->find('foO:bar');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
$this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
}


$application->add(new \Foo1Command());
$application->add(new \Foo2Command());

// Command + plural
try {
$application->find('foo:baR');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
}

// Namespace + plural
try {
$application->find('foo2:bar');
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
}
}

public function testFindAlternativeCommands()
{
$application = new Application();
Expand Down

0 comments on commit 268b618

Please sign in to comment.