You are here

public function ApplicationTest::testFindAlternativeNamespace in Zircon Profile 8

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

File

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

Class

ApplicationTest

Namespace

Symfony\Component\Console\Tests

Code

public function testFindAlternativeNamespace() {
  $application = new Application();
  $application
    ->add(new \FooCommand());
  $application
    ->add(new \Foo1Command());
  $application
    ->add(new \Foo2Command());
  $application
    ->add(new \foo3Command());
  try {
    $application
      ->find('Unknown-namespace:Unknown-command');
    $this
      ->fail('->find() throws an \\InvalidArgumentException if namespace does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\InvalidArgumentException', $e, '->find() throws an \\InvalidArgumentException if namespace does not exist');
    $this
      ->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, without alternatives');
  }
  try {
    $application
      ->find('foo2:command');
    $this
      ->fail('->find() throws an \\InvalidArgumentException if namespace does not exist');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\InvalidArgumentException', $e, '->find() throws an \\InvalidArgumentException if namespace does not exist');
    $this
      ->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative');
    $this
      ->assertRegExp('/foo/', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative : "foo"');
    $this
      ->assertRegExp('/foo1/', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
    $this
      ->assertRegExp('/foo3/', $e
      ->getMessage(), '->find() throws an \\InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
  }
}