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