Skip to content

Commit a4d2d31

Browse files
committed
[Console] Added tests for message exception when command is not available
These tests fail
1 parent b91a4a8 commit a4d2d31

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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)