3 namespace Drupal\Core\Test;
5 use Drupal\Core\DrupalKernel;
6 use Drupal\Core\Extension\Extension;
7 use Drupal\Core\Site\Settings;
8 use Symfony\Component\HttpFoundation\Request;
11 * Kernel for run-tests.sh.
13 class TestRunnerKernel extends DrupalKernel {
18 public static function createFromRequest(Request $request, $class_loader, $environment = 'test_runner', $allow_dumping = TRUE, $app_root = NULL) {
19 return parent::createFromRequest($request, $class_loader, $environment, $allow_dumping, $app_root);
25 public function __construct($environment, $class_loader, $allow_dumping = FALSE, $app_root = NULL) {
26 // Force $allow_dumping to FALSE, because the test runner kernel should
27 // always have to rebuild its container, and potentially avoid isolation
28 // issues against the tests.
29 parent::__construct($environment, $class_loader, FALSE, $app_root);
31 // Prime the module list and corresponding Extension objects.
32 // @todo Remove System module. Needed because
33 // \Drupal\Core\Datetime\DateFormatter has a (needless) dependency on the
34 // 'date_format' entity, so calls to format_date()/format_interval() cause
35 // a plugin not found exception.
41 'system' => new Extension($this->root, 'module', 'core/modules/system/system.info.yml', 'system.module'),
42 'simpletest' => new Extension($this->root, 'module', 'core/modules/simpletest/simpletest.info.yml', 'simpletest.module'),
49 public function boot() {
50 // Ensure that required Settings exist.
51 if (!Settings::getAll()) {
53 'hash_salt' => 'run-tests',
54 'container_yamls' => [],
55 // If there is no settings.php, then there is no parent site. In turn,
56 // there is no public files directory; use a custom public files path.
57 'file_public_path' => 'sites/default/files',
61 // Remove Drupal's error/exception handlers; they are designed for HTML
62 // and there is no storage nor a (watchdog) logger here.
63 restore_error_handler();
64 restore_exception_handler();
66 // In addition, ensure that PHP errors are not hidden away in logs.
67 ini_set('display_errors', TRUE);
71 $this->getContainer()->get('module_handler')->loadAll();
73 $this->getContainer()->get('test_discovery')->registerTestNamespaces();
75 // Register stream wrappers.
76 $this->getContainer()->get('stream_wrapper_manager')->register();
78 // Create the build/artifacts directory if necessary.
79 include_once $this->getAppRoot() . '/core/includes/file.inc';
80 if (!is_dir('public://simpletest')) {
81 mkdir('public://simpletest', 0777, TRUE);
88 public function discoverServiceProviders() {
89 parent::discoverServiceProviders();
90 // The test runner does not require an installed Drupal site to exist.
91 // Therefore, its environment is identical to that of the early installer.
92 $this->serviceProviderClasses['app']['Test'] = 'Drupal\Core\Installer\InstallerServiceProvider';