Commit 0f4319e4 authored by alexpott's avatar alexpott
Browse files

Issue #2528292 by Fabianx, dawehner: Decouple Error testing from relying on a...

Issue #2528292 by Fabianx, dawehner: Decouple Error testing from relying on a cached on disk-container that is created by a different Kernel
parent d9d2e5f3
......@@ -52,8 +52,6 @@
*/
class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
const CONTAINER_BASE_CLASS = '\Drupal\Core\DependencyInjection\Container';
/**
* Holds the container instance.
*
......@@ -815,7 +813,8 @@ protected function initializeContainer() {
\Drupal::setContainer($this->container);
// If needs dumping flag was set, dump the container.
if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) {
$base_class = Settings::get('container_base_class', '\Drupal\Core\DependencyInjection\Container');
if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, $base_class)) {
$this->container->get('logger.factory')->get('DrupalKernel')->notice('Container cannot be written to disk');
}
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\System\ErrorContainerRebuildKernel.
*/
namespace Drupal\system\Tests\System;
use Drupal\Core\DrupalKernel;
/**
* A kernel which produces a container which triggers an error.
*/
class ErrorContainerRebuildKernel extends DrupalKernel {
/**
* {@inheritdoc}
*/
const CONTAINER_BASE_CLASS = '\Drupal\system\Tests\Bootstrap\ErrorContainer';
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\System\ExceptionContainerRebuildKernel.
*/
namespace Drupal\system\Tests\System;
use Drupal\Core\DrupalKernel;
/**
* A kernel which produces a container which triggers an exception.
*/
class ExceptionContainerRebuildKernel extends DrupalKernel {
/**
* {@inheritdoc}
*/
const CONTAINER_BASE_CLASS = '\Drupal\system\Tests\Bootstrap\ExceptionContainer';
}
......@@ -108,10 +108,17 @@ public function testMissingDependency() {
* Tests a container which has an error.
*/
public function testErrorContainer() {
$kernel = ErrorContainerRebuildKernel::createFromRequest($this->prepareRequestForGenerator(), $this->classLoader, 'prod', TRUE);
$kernel->rebuildContainer();
$settings = [];
$settings['settings']['container_base_class'] = (object) [
'value' => '\Drupal\system\Tests\Bootstrap\ErrorContainer',
'required' => TRUE,
];
$this->writeSettings($settings);
// Need to rebuild the container, so the dumped container can be tested
// and not the container builder.
\Drupal::service('kernel')->rebuildContainer();
$this->prepareRequestForGenerator();
// Ensure that we don't use the now broken generated container on the test
// process.
\Drupal::setContainer($this->container);
......@@ -137,10 +144,17 @@ public function testErrorContainer() {
* Tests a container which has an exception really early.
*/
public function testExceptionContainer() {
$kernel = ExceptionContainerRebuildKernel::createFromRequest($this->prepareRequestForGenerator(), $this->classLoader, 'prod', TRUE);
$kernel->rebuildContainer();
$settings = [];
$settings['settings']['container_base_class'] = (object) [
'value' => '\Drupal\system\Tests\Bootstrap\ExceptionContainer',
'required' => TRUE,
];
$this->writeSettings($settings);
// Need to rebuild the container, so the dumped container can be tested
// and not the container builder.
\Drupal::service('kernel')->rebuildContainer();
$this->prepareRequestForGenerator();
// Ensure that we don't use the now broken generated container on the test
// process.
\Drupal::setContainer($this->container);
......
......@@ -632,6 +632,15 @@
*/
$settings['container_yamls'][] = __DIR__ . '/services.yml';
/**
* Override the default service container class.
*
* This is useful for example to trace the service container for performance
* tracking purposes, for testing a service container with an error condition or
* to test a service container that throws an exception.
*/
# $settings['container_base_class'] = '\Drupal\Core\DependencyInjection\Container';
/**
* Trusted host configuration.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment