Issue #2528292 by Fabianx, dawehner: Decouple Error testing from relying on a cached on disk-container that is created by a different Kernel

8.0.x
Alex Pott 2015-07-08 11:55:40 +01:00
parent d9d2e5f3d8
commit 0f4319e418
5 changed files with 31 additions and 53 deletions

View File

@ -52,8 +52,6 @@ use Symfony\Component\Routing\Route;
*/
class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
const CONTAINER_BASE_CLASS = '\Drupal\Core\DependencyInjection\Container';
/**
* Holds the container instance.
*
@ -815,7 +813,8 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
\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');
}

View File

@ -1,22 +0,0 @@
<?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';
}

View File

@ -1,22 +0,0 @@
<?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';
}

View File

@ -108,10 +108,17 @@ class UncaughtExceptionTest extends WebTestBase {
* 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 @@ class UncaughtExceptionTest extends WebTestBase {
* 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);

View File

@ -632,6 +632,15 @@ if ($settings['hash_salt']) {
*/
$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.
*