function ConsoleTest::testCommandLoader
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php \Drupal\KernelTests\Core\Console\ConsoleTest::testCommandLoader()
Tests command loader has the discovered commands.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Console/ ConsoleTest.php, line 65
Class
- ConsoleTest
- Tests integration with Symfony Console.
Namespace
Drupal\KernelTests\Core\ConsoleCode
public function testCommandLoader() : void {
/** @var \Symfony\Component\Console\CommandLoader\CommandLoaderInterface $commandLoader */
$commandLoader = \Drupal::service('console.command_loader');
$command = $commandLoader->get('example:command');
$this->assertInstanceOf(LazyCommand::class, $command);
// Ensure the command is registered as a service.
$this->assertTrue(\Drupal::hasService(ConsoleExampleCommand::class));
// Ensure the service definition is tagged as a 'console.command'.
/** @var \Symfony\Component\DependencyInjection\Definition $definition */
$definition = \Drupal::getContainer()->getDefinition(ConsoleExampleCommand::class);
$this->assertTrue($definition->hasTag('console.command'), 'ConsoleExampleCommand should be tagged as a console.command');
$this->assertTrue($definition->isAutowired(), 'ConsoleExampleCommand should be autowired');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.