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) (merged039264d2
intob91a4a83
). --------------------------------------------------------------------------- by lyrixx at 2012-08-07T15:11:47Z @travisbot You failed, not me !
This commit is contained in:
commit
268b618bfe
|
@ -496,7 +496,12 @@ class Application
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($alternatives = $this->findAlternativeNamespace($part, $abbrevs)) {
|
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);
|
$message .= implode("\n ", $alternatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,7 +576,11 @@ class Application
|
||||||
$message = sprintf('Command "%s" is not defined.', $name);
|
$message = sprintf('Command "%s" is not defined.', $name);
|
||||||
|
|
||||||
if ($alternatives = $this->findAlternativeCommands($searchName, $abbrevs)) {
|
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);
|
$message .= implode("\n ", $alternatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,52 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
public function testFindAlternativeCommands()
|
||||||
{
|
{
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
|
|
Reference in New Issue