protected function UnitTestBase::setUp

Sets up unit test environment.

Unlike Drupal\simpletest\WebTestBase::setUp(), UnitTestBase::setUp() does not install modules because tests are performed without accessing the database. Any required files must be explicitly included by the child class setUp() method.

22 calls to UnitTestBase::setUp()
AnnotatedClassDiscoveryTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php
Sets up unit test environment.
ArrayUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Common/ArrayUnitTest.php
Sets up unit test environment.
BackendChainImplementationUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/BackendChainImplementationUnitTest.php
Sets up unit test environment.
CacheDecoratorTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php
Sets up unit test environment.
ConnectionUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php
Sets up unit test environment.

... See full list

22 methods override UnitTestBase::setUp()
AnnotatedClassDiscoveryTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php
Sets up unit test environment.
ArrayUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Common/ArrayUnitTest.php
Sets up unit test environment.
BackendChainImplementationUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/BackendChainImplementationUnitTest.php
Sets up unit test environment.
CacheDecoratorTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php
Sets up unit test environment.
ConnectionUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php
Sets up unit test environment.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php, line 43
Definition of Drupal\simpletest\UnitTestBase.

Class

UnitTestBase
Base test case class for unit tests.

Namespace

Drupal\simpletest

Code

protected function setUp() {
  global $conf;

  // Create the database prefix for this test.
  $this
    ->prepareDatabasePrefix();

  // Prepare the environment for running tests.
  $this
    ->prepareEnvironment();
  if (!$this->setupEnvironment) {
    return FALSE;
  }

  // Reset all statics and variables to perform tests in a clean environment.
  $conf = array();
  drupal_static_reset();

  // Enforce an empty module list.
  module_list(NULL, array());
  $conf['file_public_path'] = $this->public_files_directory;

  // Change the database prefix.
  // All static variables need to be reset before the database prefix is
  // changed, since Drupal\Core\Utility\CacheArray implementations attempt to
  // write back to persistent caches when they are destructed.
  $this
    ->changeDatabasePrefix();
  if (!$this->setupDatabasePrefix) {
    return FALSE;
  }

  // Set user agent to be consistent with WebTestBase.
  $_SERVER['HTTP_USER_AGENT'] = $this->databasePrefix;
  $this->setup = TRUE;
}