You are here

public function ApplicationTest::testFindAlternativeExceptionMessageMultiple 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::testFindAlternativeExceptionMessageMultiple()

File

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

Class

ApplicationTest

Namespace

Symfony\Component\Console\Tests

Code

public function testFindAlternativeExceptionMessageMultiple() {
  $application = new Application();
  $application
    ->add(new \FooCommand());
  $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');
    $this
      ->assertRegExp('/foo1:bar/', $e
      ->getMessage());
    $this
      ->assertRegExp('/foo:bar/', $e
      ->getMessage());
  }

  // 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');
    $this
      ->assertRegExp('/foo1/', $e
      ->getMessage());
  }
  $application
    ->add(new \Foo3Command());
  $application
    ->add(new \Foo4Command());

  // Subnamespace + plural
  try {
    $a = $application
      ->find('foo3:');
    $this
      ->fail('->find() should throw an \\InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\InvalidArgumentException', $e);
    $this
      ->assertRegExp('/foo3:bar/', $e
      ->getMessage());
    $this
      ->assertRegExp('/foo3:bar:toh/', $e
      ->getMessage());
  }
}