TestRunnerKernel.php 3.2 KB

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