Commit 722c8dd2 authored by alexpott's avatar alexpott

Issue #2409247 by znerol: Generated proxy classes break DrupalKernelTest when running from the UI

parent ba831b2c
......@@ -667,6 +667,15 @@ protected function getClassName() {
return implode('_', $parts);
}
/**
* Returns the container class namespace based on the environment.
*
* @return string
* The class name.
*/
protected function getClassNamespace() {
return 'Drupal\\Core\\DependencyInjection\\Container\\' . $this->environment;
}
/**
* Returns the kernel parameters.
......@@ -704,16 +713,14 @@ protected function initializeContainer($rebuild = FALSE) {
// If the module list hasn't already been set in updateModules and we are
// not forcing a rebuild, then try and load the container from the disk.
if (empty($this->moduleList) && !$rebuild) {
$class = $this->getClassName();
$cache_file = $class . '.php';
$fully_qualified_class_name = '\\' . $this->getClassNamespace() . '\\' . $this->getClassName();
// First, try to load from storage.
if (!class_exists($class, FALSE)) {
$this->storage()->load($cache_file);
if (!class_exists($fully_qualified_class_name, FALSE)) {
$this->storage()->load($this->getClassName() . '.php');
}
// If the load succeeded or the class already existed, use it.
if (class_exists($class, FALSE)) {
$fully_qualified_class_name = '\\' . $class;
if (class_exists($fully_qualified_class_name, FALSE)) {
$container = new $fully_qualified_class_name;
}
}
......@@ -1093,7 +1100,12 @@ protected function dumpDrupalContainer(ContainerBuilder $container, $baseClass)
$dumper = new PhpDumper($container);
$dumper->setProxyDumper(new ProxyDumper(new ProxyBuilder()));
$class = $this->getClassName();
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
$namespace = $this->getClassNamespace();
$content = $dumper->dump([
'class' => $class,
'base_class' => $baseClass,
'namespace' => $namespace,
]);
return $this->storage()->save($class . '.php', $content);
}
......
......@@ -153,4 +153,27 @@ public function testCompileDIC() {
));
}
/**
* Test repeated loading of compiled DIC with different environment.
*/
public function testRepeatedBootWithDifferentEnvironment() {
$request = Request::createFromGlobals();
$class_loader = require DRUPAL_ROOT . '/core/vendor/autoload.php';
$environments = [
'testing1',
'testing1',
'testing2',
'testing2',
];
foreach ($environments as $environment) {
$kernel = DrupalKernel::createFromRequest($request, $class_loader, $environment);
$this->settingsSet('hash_salt', $this->databasePrefix);
$kernel->boot();
}
$this->pass('Repeatedly loaded compiled DIC with different environment');
}
}
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