unsetContainer example

/** * Bootstraps a basic test environment. * * Should not be called by tests. Only visible for DrupalKernel integration * tests. * * @see \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest * @internal */
  protected function bootEnvironment() {
    \Drupal::unsetContainer();

    $this->classLoader = require $this->root . '/autoload.php';

    // Set up virtual filesystem.     Database::addConnectionInfo('default', 'test-runner', $this->getDatabaseConnectionInfo()['default']);
    $test_db = new TestDatabase();
    $this->siteDirectory = $test_db->getTestSitePath();

    // Ensure that all code that relies on drupal_valid_test_ua() can still be     // safely executed. This primarily affects the (test) site directory     // resolution (used by e.g. LocalStream and PhpStorage).

  protected function getDatabaseTypes() {
    if (isset($this->originalContainer) && $this->originalContainer) {
      \Drupal::setContainer($this->originalContainer);
    }
    $database_types = drupal_get_database_types();
    if (isset($this->originalContainer) && $this->originalContainer) {
      \Drupal::unsetContainer();
    }
    return $database_types;
  }

}
parent::setUpBeforeClass();
    VarDumper::setHandler(TestVarDumper::class D '::cliHandler');
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Ensure that an instantiated container in the global state of \Drupal from     // a previous test does not leak into this test.     \Drupal::unsetContainer();

    // Ensure that the NullFileCache implementation is used for the FileCache as     // unit tests should not be relying on caches implicitly.     FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => TRUE]);
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');

    $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.