protected function DrupalUnitTestBase::setUp

Sets up Drupal unit test environment.

Overrides UnitTestBase::setUp

See also

DrupalUnitTestBase::$modules

DrupalUnitTestBase

43 calls to DrupalUnitTestBase::setUp()
ActionUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Action/ActionUnitTest.php
Sets up Drupal unit test environment.
BlockInterfaceTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php
Sets up Drupal unit test environment.
BlockStorageUnitTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
Sets up Drupal unit test environment.
CKEditorPluginManagerTest::setUp in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
Sets up Drupal unit test environment.
CKEditorTest::setUp in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
Sets up Drupal unit test environment.

... See full list

44 methods override DrupalUnitTestBase::setUp()
ActionUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Action/ActionUnitTest.php
Sets up Drupal unit test environment.
BlockInterfaceTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php
Sets up Drupal unit test environment.
BlockStorageUnitTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
Sets up Drupal unit test environment.
CKEditorPluginManagerTest::setUp in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
Sets up Drupal unit test environment.
CKEditorTest::setUp in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
Sets up Drupal unit test environment.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php, line 79
Contains Drupal\simpletest\DrupalUnitTestBase.

Class

DrupalUnitTestBase
Base test case class for Drupal unit tests.

Namespace

Drupal\simpletest

Code

protected function setUp() {

  // Copy/prime extension file lists once to avoid filesystem scans.
  if (!isset($this->moduleFiles)) {
    $this->moduleFiles = \Drupal::state()
      ->get('system.module.files') ?: array();
    $this->themeFiles = \Drupal::state()
      ->get('system.theme.files') ?: array();
    $this->themeData = \Drupal::state()
      ->get('system.theme.data') ?: array();
  }
  $this->keyValueFactory = new KeyValueMemoryFactory();
  parent::setUp();

  // Build a minimal, partially mocked environment for unit tests.
  $this
    ->containerBuild(drupal_container());

  // Make sure it survives kernel rebuilds.
  $GLOBALS['conf']['container_bundles'][] = 'Drupal\\simpletest\\TestBundle';
  \Drupal::state()
    ->set('system.module.files', $this->moduleFiles);
  \Drupal::state()
    ->set('system.theme.files', $this->themeFiles);
  \Drupal::state()
    ->set('system.theme.data', $this->themeData);

  // Bootstrap the kernel.
  // No need to dump it; this test runs in-memory.
  $this->kernel = new DrupalKernel('unit_testing', TRUE, drupal_classloader(), FALSE);
  $this->kernel
    ->boot();

  // Collect and set a fixed module list.
  $class = get_class($this);
  $modules = array();
  while ($class) {
    if (property_exists($class, 'modules')) {

      // Only add the modules, if the $modules property was not inherited.
      $rp = new \ReflectionProperty($class, 'modules');
      if ($rp->class == $class) {
        $modules[$class] = $class::$modules;
      }
    }
    $class = get_parent_class($class);
  }

  // Modules have been collected in reverse class hierarchy order; modules
  // defined by base classes should be sorted first. Then, merge the results
  // together.
  $modules = array_reverse($modules);
  $modules = call_user_func_array('array_merge_recursive', $modules);
  $this
    ->enableModules($modules, FALSE);

  // In order to use theme functions default theme config needs to exist.
  config('system.theme')
    ->set('default', 'stark');
}