You are here

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

File

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

Class

ApplicationTest

Namespace

Symfony\Component\Console\Tests

Code

public function testSetCatchExceptions() {
  $application = $this
    ->getMock('Symfony\\Component\\Console\\Application', array(
    'getTerminalWidth',
  ));
  $application
    ->setAutoExit(false);
  $application
    ->expects($this
    ->any())
    ->method('getTerminalWidth')
    ->will($this
    ->returnValue(120));
  $tester = new ApplicationTester($application);
  $application
    ->setCatchExceptions(true);
  $tester
    ->run(array(
    'command' => 'foo',
  ), array(
    'decorated' => false,
  ));
  $this
    ->assertStringEqualsFile(self::$fixturesPath . '/application_renderexception1.txt', $tester
    ->getDisplay(true), '->setCatchExceptions() sets the catch exception flag');
  $application
    ->setCatchExceptions(false);
  try {
    $tester
      ->run(array(
      'command' => 'foo',
    ), array(
      'decorated' => false,
    ));
    $this
      ->fail('->setCatchExceptions() sets the catch exception flag');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('\\Exception', $e, '->setCatchExceptions() sets the catch exception flag');
    $this
      ->assertEquals('Command "foo" is not defined.', $e
      ->getMessage(), '->setCatchExceptions() sets the catch exception flag');
  }
}