function ConsoleTest::testApplication

Same name and namespace in other branches
  1. main core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php \Drupal\KernelTests\Core\Console\ConsoleTest::testApplication()

Tests the application wrapped by symfony/runtime.

File

core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php, line 40

Class

ConsoleTest
Tests integration with Symfony Console.

Namespace

Drupal\KernelTests\Core\Console

Code

public function testApplication() : void {
  $tester = $this->applicationTester();
  $code = $tester->run([
    'command' => 'example:command',
  ]);
  $this->assertEquals(Command::SUCCESS, $code, $tester->getDisplay());
  $this->assertStringContainsString('Dependency injection test: ' . TestInjection::class, $tester->getDisplay());
  $this->assertStringContainsString('Option test: No', $tester->getDisplay());
  $this->assertStringContainsString('Argument test: No', $tester->getDisplay());
  $this->assertStringContainsString('[OK] Done', $tester->getDisplay());
  // Test the command registered via configure() not via the #AsCommand attribute.
  $tester = $this->applicationTester();
  $code = $tester->run([
    'command' => 'example:command-configured',
  ]);
  $this->assertEquals(Command::SUCCESS, $code, $tester->getDisplay());
  $this->assertStringContainsString('Done with configured command.', $tester->getDisplay());
  // Test the example private command.
  $tester = $this->applicationTester();
  $code = $tester->run([
    'command' => 'example:command-private',
  ]);
  $this->assertEquals(Command::SUCCESS, $code, $tester->getDisplay());
  $this->assertStringContainsString('Done with private command.', $tester->getDisplay());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.