class KernelTestDrupalKernel
Subclass of DrupalKernel for kernel testing.
This class extends the DrupalKernel to allow re-use of the dependency injection container between kernel test methods.
@internal only use in tests.
Hierarchy
- class \Drupal\Core\DrupalKernel implements \Drupal\Core\DrupalKernelInterface, \Symfony\Component\HttpKernel\TerminableInterface uses \Drupal\Core\Installer\InstallerRedirectTrait
- class \Drupal\Core\Test\KernelTestDrupalKernel extends \Drupal\Core\DrupalKernel
Expanded class hierarchy of KernelTestDrupalKernel
1 file declares its use of KernelTestDrupalKernel
- KernelTestBase.php in core/
tests/ Drupal/ KernelTests/ KernelTestBase.php
File
-
core/
lib/ Drupal/ Core/ Test/ KernelTestDrupalKernel.php, line 18
Namespace
Drupal\Core\TestView source
class KernelTestDrupalKernel extends DrupalKernel {
/**
* Whether the container should be retrieved from cache.
*
* Only overrides when it's TRUE, FALSE does nothing.
*/
protected bool $overrideUseCache = FALSE;
/**
* A cache suffix to increment on rebuilds.
*/
protected int $cacheSuffix = 0;
/**
* Sets whether the container should be rebuilt.
*/
public function setContainerNeedsRebuild(bool $rebuild) : void {
$this->containerNeedsRebuild = $rebuild;
}
/**
* Resets the cache suffix to 0.
*/
public function resetCacheSuffix() : void {
$this->cacheSuffix = 0;
}
/**
* Sets whether the container should be retrieved from cache.
*/
public function setOverrideUseCache(bool $use) : void {
$this->overrideUseCache = $use;
}
/**
* {@inheritdoc}
*/
protected function getContainerCacheKey() {
$key = parent::getContainerCacheKey();
// Vary by the suffix, so that a container rebuilt during a test method is
// cached under its own key and does not overwrite the initial container
// that the other test methods of the class load.
$key .= ':' . $this->cacheSuffix;
return $key;
}
/**
* {@inheritdoc}
*/
protected function getContainerFromCacheIfCacheable() : ?array {
if ($this->overrideUseCache) {
// Only override once.
$this->overrideUseCache = FALSE;
return $this->getCachedContainerDefinition();
}
return parent::getContainerFromCacheIfCacheable();
}
/**
* {@inheritdoc}
*/
public function rebuildContainer() {
$this->cacheSuffix++;
return parent::rebuildContainer();
}
/**
* {@inheritdoc}
*/
public function resetContainer() : ContainerInterface {
$this->cacheSuffix++;
return parent::resetContainer();
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| DrupalKernel::$allowDumping | protected | property | Whether the container can be dumped. | ||
| DrupalKernel::$booted | protected | property | Whether the kernel has been booted. | ||
| DrupalKernel::$bootstrapContainer | protected | property | Holds the bootstrap container. | ||
| DrupalKernel::$bootstrapContainerClass | protected | property | Holds the class used for instantiating the bootstrap container. | ||
| DrupalKernel::$classLoader | protected | property | The class loader object. | ||
| DrupalKernel::$configStorage | protected | property | Config storage object used for reading enabled modules configuration. | ||
| DrupalKernel::$container | protected | property | Holds the container instance. | ||
| DrupalKernel::$containerNeedsDumping | protected | property | Whether the container needs to be dumped once booting is complete. | ||
| DrupalKernel::$containerNeedsRebuild | protected | property | Whether the container needs to be rebuilt the next time it is initialized. | ||
| DrupalKernel::$defaultBootstrapContainerDefinition | protected | property | Holds the default bootstrap container definition. | ||
| DrupalKernel::$environment | protected | property | The environment, e.g. 'testing', 'install'. | ||
| DrupalKernel::$isEnvironmentInitialized | protected static | property | Whether the PHP environment has been initialized. | ||
| DrupalKernel::$moduleData | protected | property | List of available modules and installation profiles. | ||
| DrupalKernel::$moduleList | protected | property | Holds the list of enabled modules. | ||
| DrupalKernel::$phpArrayDumperClass | protected | property | Holds the class used for dumping the container to a PHP array. | ||
| DrupalKernel::$prepared | protected | property | Whether essential services have been set up properly by preHandle(). | ||
| DrupalKernel::$root | protected | property | The app root. | ||
| DrupalKernel::$serviceProviderClasses | protected | property | List of discovered service provider class names or objects. | ||
| DrupalKernel::$serviceProviders | protected | property | List of instantiated service provider classes. | ||
| DrupalKernel::$serviceYamls | protected | property | List of discovered services.yml path names. | ||
| DrupalKernel::$sitePath | protected | property | The site path directory. | ||
| DrupalKernel::$themeExtensions | protected | property | List of available themes. | ||
| DrupalKernel::$themeList | protected | property | Holds the list of enabled themes from core.extension config. | ||
| DrupalKernel::addServiceFiles | protected | function | Add service files. | ||
| DrupalKernel::attachSynthetic | protected | function | Attach synthetic values on to kernel. | ||
| DrupalKernel::boot | public | function | Boots the current kernel. | Overrides DrupalKernelInterface::boot | 1 |
| DrupalKernel::bootEnvironment | public static | function | Setup a consistent PHP environment. | ||
| DrupalKernel::cacheDrupalContainer | protected | function | Stores the container definition in a cache. | 1 | |
| DrupalKernel::classLoaderAddMultiplePsr4 | protected | function | Registers a list of namespaces with PSR-4 directories for class loading. | ||
| DrupalKernel::compileContainer | protected | function | Compiles a new service container. | ||
| DrupalKernel::createFromRequest | public static | function | Create a DrupalKernel object from a request. | 1 | |
| DrupalKernel::discoverServiceProviders | public | function | Discovers available serviceProviders. | Overrides DrupalKernelInterface::discoverServiceProviders | 2 |
| DrupalKernel::findSitePath | public static | function | Returns the appropriate site directory for a request. | ||
| DrupalKernel::getAppRoot | public | function | Gets the app root. | Overrides DrupalKernelInterface::getAppRoot | |
| DrupalKernel::getCachedContainerDefinition | public | function | Returns the cached container definition - if any. | Overrides DrupalKernelInterface::getCachedContainerDefinition | |
| DrupalKernel::getConfigStorage | protected | function | Gets the active configuration storage to use during building the container. | 1 | |
| DrupalKernel::getContainer | public | function | Gets the current container. | Overrides DrupalKernelInterface::getContainer | |
| DrupalKernel::getContainerBuilder | protected | function | Gets a new ContainerBuilder instance used to build the service container. | ||
| DrupalKernel::getExtensionFileNames | protected | function | Gets the filenames for each enabled extension. | ||
| DrupalKernel::getExtensionNamespacesPsr4 | protected | function | Gets the PSR-4 base directories for extension namespaces. | ||
| DrupalKernel::getExtensions | protected | function | Get the core.extension config object. | 1 | |
| DrupalKernel::getExtensionsParameter | protected | function | Returns an array of Extension class parameters for all enabled extensions. | ||
| DrupalKernel::getHttpKernel | protected | function | Gets a http kernel from the container. | ||
| DrupalKernel::getInstallProfile | protected | function | Gets the active install profile. | 1 | |
| DrupalKernel::getKernelParameters | protected | function | Returns the kernel parameters. | ||
| DrupalKernel::getServiceProviders | public | function | Returns all registered service providers. | Overrides DrupalKernelInterface::getServiceProviders | |
| DrupalKernel::getServicesToPersist | protected | function | Returns service instances to persist from an old container to a new one. | ||
| DrupalKernel::getSitePath | public | function | Gets the site path directory. | Overrides DrupalKernelInterface::getSitePath | |
| DrupalKernel::guessApplicationRoot | protected static | function | Determine the application root directory based on this file's location. | ||
| DrupalKernel::handle | public | function | 1 | ||
| DrupalKernel::handleException | protected | function | Converts an exception into a response. | ||
| DrupalKernel::initializeContainer | protected | function | Initializes the service container. | 2 | |
| DrupalKernel::initializeEphemeralSession | protected | function | Initializes a session backed by in-memory store and puts it on the request. | ||
| DrupalKernel::initializeRequestGlobals | protected | function | Bootstraps the legacy global request variables. | ||
| DrupalKernel::initializeServiceProviders | protected | function | Registers all service providers to the kernel. | ||
| DrupalKernel::initializeSettings | protected | function | Locate site path and initialize settings singleton. | ||
| DrupalKernel::invalidateContainer | public | function | Invalidate the service container for the next request. | Overrides DrupalKernelInterface::invalidateContainer | |
| DrupalKernel::loadLegacyIncludes | public | function | Helper method that loads legacy Drupal include files. | Overrides DrupalKernelInterface::loadLegacyIncludes | |
| DrupalKernel::moduleData | protected | function | Returns module data on the filesystem. | ||
| DrupalKernel::persistServices | protected | function | Moves persistent service instances into a new container. | ||
| DrupalKernel::preHandle | public | function | Helper method that does request related initialization. | Overrides DrupalKernelInterface::preHandle | |
| DrupalKernel::setExtensionData | private | function | Sets extension data to class properties using ExtensionDiscovery. | ||
| DrupalKernel::setSitePath | public | function | Set the current site path directory. | Overrides DrupalKernelInterface::setSitePath | |
| DrupalKernel::setupDrupalTestInChildSite | public static | function | Define the DRUPAL_TEST_IN_CHILD_SITE constant as appropriate. | ||
| DrupalKernel::setupTrustedHosts | protected static | function | Sets up the lists of trusted HTTP Host headers. | ||
| DrupalKernel::shutdown | public | function | Shuts down the kernel. | Overrides DrupalKernelInterface::shutdown | |
| DrupalKernel::terminate | public | function | |||
| DrupalKernel::themeExtensions | protected | function | Returns theme data on the filesystem. | ||
| DrupalKernel::updateModules | public | function | Implements Drupal\Core\DrupalKernelInterface::updateModules(). | Overrides DrupalKernelInterface::updateModules | |
| DrupalKernel::updateThemes | public | function | Updates the kernel's list of themes to the new list. | Overrides DrupalKernelInterface::updateThemes | 1 |
| DrupalKernel::validateHostname | public static | function | Validates the hostname supplied from the HTTP request. | ||
| DrupalKernel::validateHostnameLength | protected static | function | Validates a hostname length. | ||
| DrupalKernel::__construct | public | function | Constructs a DrupalKernel object. | 2 | |
| DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED | constant | Event fired when the service container finished initializing in subrequest. | |||
| InstallerRedirectTrait::isCli | protected | function | Returns whether the current PHP process runs on CLI. | ||
| InstallerRedirectTrait::shouldRedirectToInstaller | protected | function | Determines if an exception handler should redirect to the installer. | ||
| KernelTestDrupalKernel::$cacheSuffix | protected | property | A cache suffix to increment on rebuilds. | ||
| KernelTestDrupalKernel::$overrideUseCache | protected | property | Whether the container should be retrieved from cache. | ||
| KernelTestDrupalKernel::getContainerCacheKey | protected | function | Returns the container cache key based on the environment. | Overrides DrupalKernel::getContainerCacheKey | |
| KernelTestDrupalKernel::getContainerFromCacheIfCacheable | protected | function | Gets the cached container definition if the cache may be used. | Overrides DrupalKernel::getContainerFromCacheIfCacheable | |
| KernelTestDrupalKernel::rebuildContainer | public | function | Force a container rebuild. | Overrides DrupalKernel::rebuildContainer | |
| KernelTestDrupalKernel::resetCacheSuffix | public | function | Resets the cache suffix to 0. | ||
| KernelTestDrupalKernel::resetContainer | public | function | Force a container reset. | Overrides DrupalKernel::resetContainer | |
| KernelTestDrupalKernel::setContainerNeedsRebuild | public | function | Sets whether the container should be rebuilt. | ||
| KernelTestDrupalKernel::setOverrideUseCache | public | function | Sets whether the container should be retrieved from cache. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.