function ConsoleTest::testConsoleCommand
Same name and namespace in other branches
- main core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php \Drupal\KernelTests\Core\Console\ConsoleTest::testConsoleCommand()
Tests running a console command.
Tests that the command is registered to the container, can be run, returns the correct status code, that autowiring dependencies inside the command works, and verifies the expected output based on the supplied options and arguments.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Console/ ConsoleTest.php, line 99
Class
- ConsoleTest
- Tests integration with Symfony Console.
Namespace
Drupal\KernelTests\Core\ConsoleCode
public function testConsoleCommand() : void {
$tester = $this->applicationTester();
$code = $tester->run([
'command' => 'example:command',
'argument-test' => 'Foo',
'--option-test' => TRUE,
], [
'capture_stderr_separately' => TRUE,
]);
$this->assertEquals(Command::SUCCESS, $code, $tester->getErrorOutput());
$this->assertStringContainsString('Dependency injection test: ' . TestInjection::class, $tester->getErrorOutput());
$this->assertStringContainsString('Option test: Yes', $tester->getErrorOutput());
$this->assertStringContainsString('Argument test: Yes', $tester->getErrorOutput());
$this->assertStringContainsString('[OK] Done', $tester->getDisplay());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.