You are here

public function ApplicationTest::testFindAlternativeCommands in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/console/Tests/ApplicationTest.php \Symfony\Component\Console\Tests\ApplicationTest::testFindAlternativeCommands()

File

vendor/symfony/console/Tests/ApplicationTest.php, line 376

Class

ApplicationTest

Namespace

Symfony\Component\Console\Tests

Code

public function testFindAlternativeCommands() {
  $application = new Application();
  $application
    ->add(new \FooCommand());
  $application
    ->add(new \Foo1Command());
  $application
    ->add(new \Foo2Command());
  try {
    $application
      ->find($commandName = 'Unknown command');
    $this
      ->fail('->find() throws an \\InvalidArgumentException if command does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\InvalidArgumentException', $e, '->find() throws an \\InvalidArgumentException if command does not exist');
    $this
      ->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if command does not exist, without alternatives');
  }

  // Test if "bar1" command throw an "\InvalidArgumentException" and does not contain
  // "foo:bar" as alternative because "bar1" is too far from "foo:bar"
  try {
    $application
      ->find($commandName = 'bar1');
    $this
      ->fail('->find() throws an \\InvalidArgumentException if command does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\InvalidArgumentException', $e, '->find() throws an \\InvalidArgumentException if command does not exist');
    $this
      ->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if command does not exist, with alternatives');
    $this
      ->assertRegExp('/afoobar1/', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if command does not exist, with alternative : "afoobar1"');
    $this
      ->assertRegExp('/foo:bar1/', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if command does not exist, with alternative : "foo:bar1"');
    $this
      ->assertNotRegExp('/foo:bar(?>!1)/', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if command does not exist, without "foo:bar" alternative');
  }
}