Skip to content
Snippets Groups Projects
Commit 5f158ec5 authored by catch's avatar catch
Browse files

Issue #2909164 by drunken monkey, dawehner: Fatal error with stub container in...

Issue #2909164 by drunken monkey, dawehner: Fatal error with stub container in DependencySerializationTrait::__wakeup()
parent d4006a68
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -45,11 +45,19 @@ public function __sleep() {
*/
public function __wakeup() {
// Tests in isolation potentially unserialize in the parent process.
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP']) && !\Drupal::hasContainer()) {
$phpunit_bootstrap = isset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
if ($phpunit_bootstrap && !\Drupal::hasContainer()) {
return;
}
$container = \Drupal::getContainer();
foreach ($this->_serviceIds as $key => $service_id) {
// In rare cases, when test data is serialized in the parent process,
// there is a service container but it doesn't contain all expected
// services. To avoid fatal errors during the wrap-up of failing tests, we
// check for this case, too.
if ($phpunit_bootstrap && !$container->has($service_id)) {
continue;
}
$this->$key = $container->get($service_id);
}
$this->_serviceIds = [];
......
......@@ -44,6 +44,29 @@ public function testSerialization() {
$this->assertEmpty($dependencySerialization->getServiceIds());
}
/**
* @covers ::__sleep
* @covers ::__wakeup
*/
public function testSerializationWithMissingService() {
// Create a pseudo service and dependency injected object.
$service = new \stdClass();
$service->_serviceId = 'test_service_not_existing';
$container = new Container();
$container->set('test_service', $service);
$container->set('service_container', $container);
\Drupal::setContainer($container);
$dependencySerialization = new DependencySerializationTestDummy($service);
$dependencySerialization->setContainer($container);
$string = serialize($dependencySerialization);
/** @var \Drupal\Tests\Core\DependencyInjection\DependencySerializationTestDummy $dependencySerialization */
$dependencySerialization = unserialize($string);
$this->assertSame($container, $dependencySerialization->container);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment