Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Test / TestRunnerKernel.php
1 <?php
2
3 namespace Drupal\Core\Test;
4
5 use Drupal\Core\DrupalKernel;
6 use Drupal\Core\Extension\Extension;
7 use Drupal\Core\Site\Settings;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * Kernel for run-tests.sh.
12  */
13 class TestRunnerKernel extends DrupalKernel {
14
15   /**
16    * {@inheritdoc}
17    */
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);
20   }
21
22   /**
23    * {@inheritdoc}
24    */
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);
30
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.
36     $this->moduleList = [
37       'system' => 0,
38       'simpletest' => 0,
39     ];
40     $this->moduleData = [
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'),
43     ];
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function boot() {
50     // Ensure that required Settings exist.
51     if (!Settings::getAll()) {
52       new Settings([
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',
58       ]);
59     }
60
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();
65
66     // In addition, ensure that PHP errors are not hidden away in logs.
67     ini_set('display_errors', TRUE);
68
69     parent::boot();
70
71     $this->getContainer()->get('module_handler')->loadAll();
72
73     $this->getContainer()->get('test_discovery')->registerTestNamespaces();
74
75     // Register stream wrappers.
76     $this->getContainer()->get('stream_wrapper_manager')->register();
77
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);
82     }
83   }
84
85   /**
86    * {@inheritdoc}
87    */
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';
93   }
94
95 }