Loading core/lib/Drupal/Core/Command/DrupalApplication.php +1 −6 Original line number Diff line number Diff line Loading @@ -95,12 +95,7 @@ protected function bootstrap(): bool { // Discovery can get out of whack if cleared caches and try to run this // command without a web request priming discovery. chdir(\DRUPAL_ROOT); // We need to not load a cached copy of the container from disk. For // example, inside Kernel tests, we need to fully build the container so // we discover and register commands, instead of reusing the container // from the Kernel test itself. Therefore, we pass `FALSE` for the // `$allow_dumping` parameter here. $kernel = new DrupalKernel('prod', $this->classloader, FALSE); $kernel = new DrupalKernel($this->context['kernel.environment'] ?? 'prod', $this->classloader, $this->context['kernel.allow_dumping'] ?? TRUE); // We tried calling `DrupalKernel::bootEnvironment()` right here to setup // some common environment and PHP initialization steps. However, that // method also calls `set_error_handler('_drupal_error_handler')` which Loading core/modules/system/tests/src/Kernel/Command/StatusCommandTest.php +2 −11 Original line number Diff line number Diff line Loading @@ -4,13 +4,13 @@ namespace Drupal\Tests\system\Kernel\Command; use Drupal\KernelTests\DrupalApplicationTesterTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\system\Command\StatusCommand; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\ApplicationTester; /** * Tests the 'system:status' command. Loading @@ -19,6 +19,7 @@ #[RunTestsInSeparateProcesses] #[CoversClass(StatusCommand::class)] class StatusCommandTest extends KernelTestBase { use DrupalApplicationTesterTrait; /** * {@inheritdoc} Loading Loading @@ -101,14 +102,4 @@ protected function assertStringContainsStringNoWhitespace(string $needle, string $this->assertStringContainsString($normalized_needle, $normalized_haystack, $message ?? ''); } /** * Build our ApplicationTester. */ private function applicationTester(array $context = []): ApplicationTester { $application = include __DIR__ . '/../../../../../../../vendor/bin/dr'; $application = $application($context); $application->setAutoExit(FALSE); return new ApplicationTester($application); } } core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php +2 −11 Original line number Diff line number Diff line Loading @@ -9,13 +9,13 @@ use Drupal\console_test\Command\ConsoleExampleConfigureCommand; use Drupal\console_test\Command\ConsoleExamplePrivateCommand; use Drupal\Core\DependencyInjection\Compiler\ConsoleCompilerPass; use Drupal\KernelTests\DrupalApplicationTesterTrait; use Drupal\KernelTests\KernelTestBase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\LazyCommand; use Symfony\Component\Console\Tester\ApplicationTester; /** * Tests integration with Symfony Console. Loading @@ -25,6 +25,7 @@ #[CoversClass(ConsoleCompilerPass::class)] #[CoversClass(ConsoleExampleCommand::class)] class ConsoleTest extends KernelTestBase { use DrupalApplicationTesterTrait; /** * {@inheritdoc} Loading Loading @@ -116,14 +117,4 @@ public function testSubdirectoryCommand(): void { $this->assertStringContainsString('[OK] Done', $tester->getDisplay()); } /** * Builds an ApplicationTester to invoke `vendor/bin/dr`. */ private function applicationTester(array $context = []): ApplicationTester { $application = include __DIR__ . '/../../../../../../vendor/bin/dr'; $application = $application($context); $application->setAutoExit(FALSE); return new ApplicationTester($application); } } core/tests/Drupal/KernelTests/DrupalApplicationTesterTrait.php 0 → 100644 +26 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\KernelTests; use Symfony\Component\Console\Tester\ApplicationTester; /** * Trait to help with testing the drupal console. */ trait DrupalApplicationTesterTrait { /** * Build our ApplicationTester. */ private function applicationTester(array $context = []): ApplicationTester { $application = include __DIR__ . '/../../../../vendor/bin/dr'; $context['kernel.environment'] = 'testing'; $context['kernel.allow_dumping'] = FALSE; $application = $application($context); $application->setAutoExit(FALSE); return new ApplicationTester($application); } } Loading
core/lib/Drupal/Core/Command/DrupalApplication.php +1 −6 Original line number Diff line number Diff line Loading @@ -95,12 +95,7 @@ protected function bootstrap(): bool { // Discovery can get out of whack if cleared caches and try to run this // command without a web request priming discovery. chdir(\DRUPAL_ROOT); // We need to not load a cached copy of the container from disk. For // example, inside Kernel tests, we need to fully build the container so // we discover and register commands, instead of reusing the container // from the Kernel test itself. Therefore, we pass `FALSE` for the // `$allow_dumping` parameter here. $kernel = new DrupalKernel('prod', $this->classloader, FALSE); $kernel = new DrupalKernel($this->context['kernel.environment'] ?? 'prod', $this->classloader, $this->context['kernel.allow_dumping'] ?? TRUE); // We tried calling `DrupalKernel::bootEnvironment()` right here to setup // some common environment and PHP initialization steps. However, that // method also calls `set_error_handler('_drupal_error_handler')` which Loading
core/modules/system/tests/src/Kernel/Command/StatusCommandTest.php +2 −11 Original line number Diff line number Diff line Loading @@ -4,13 +4,13 @@ namespace Drupal\Tests\system\Kernel\Command; use Drupal\KernelTests\DrupalApplicationTesterTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\system\Command\StatusCommand; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\ApplicationTester; /** * Tests the 'system:status' command. Loading @@ -19,6 +19,7 @@ #[RunTestsInSeparateProcesses] #[CoversClass(StatusCommand::class)] class StatusCommandTest extends KernelTestBase { use DrupalApplicationTesterTrait; /** * {@inheritdoc} Loading Loading @@ -101,14 +102,4 @@ protected function assertStringContainsStringNoWhitespace(string $needle, string $this->assertStringContainsString($normalized_needle, $normalized_haystack, $message ?? ''); } /** * Build our ApplicationTester. */ private function applicationTester(array $context = []): ApplicationTester { $application = include __DIR__ . '/../../../../../../../vendor/bin/dr'; $application = $application($context); $application->setAutoExit(FALSE); return new ApplicationTester($application); } }
core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php +2 −11 Original line number Diff line number Diff line Loading @@ -9,13 +9,13 @@ use Drupal\console_test\Command\ConsoleExampleConfigureCommand; use Drupal\console_test\Command\ConsoleExamplePrivateCommand; use Drupal\Core\DependencyInjection\Compiler\ConsoleCompilerPass; use Drupal\KernelTests\DrupalApplicationTesterTrait; use Drupal\KernelTests\KernelTestBase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\LazyCommand; use Symfony\Component\Console\Tester\ApplicationTester; /** * Tests integration with Symfony Console. Loading @@ -25,6 +25,7 @@ #[CoversClass(ConsoleCompilerPass::class)] #[CoversClass(ConsoleExampleCommand::class)] class ConsoleTest extends KernelTestBase { use DrupalApplicationTesterTrait; /** * {@inheritdoc} Loading Loading @@ -116,14 +117,4 @@ public function testSubdirectoryCommand(): void { $this->assertStringContainsString('[OK] Done', $tester->getDisplay()); } /** * Builds an ApplicationTester to invoke `vendor/bin/dr`. */ private function applicationTester(array $context = []): ApplicationTester { $application = include __DIR__ . '/../../../../../../vendor/bin/dr'; $application = $application($context); $application->setAutoExit(FALSE); return new ApplicationTester($application); } }
core/tests/Drupal/KernelTests/DrupalApplicationTesterTrait.php 0 → 100644 +26 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\KernelTests; use Symfony\Component\Console\Tester\ApplicationTester; /** * Trait to help with testing the drupal console. */ trait DrupalApplicationTesterTrait { /** * Build our ApplicationTester. */ private function applicationTester(array $context = []): ApplicationTester { $application = include __DIR__ . '/../../../../vendor/bin/dr'; $context['kernel.environment'] = 'testing'; $context['kernel.allow_dumping'] = FALSE; $application = $application($context); $application->setAutoExit(FALSE); return new ApplicationTester($application); } }