Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / DependencyInjection / DependencySerializationTrait.php
index 7f3cb5d6f98c29a16cede65edb5668e7ec636436..37e7f821b0854e95e31ad34529583f728d7d6715 100644 (file)
@@ -45,11 +45,19 @@ trait DependencySerializationTrait {
    */
   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 = [];