diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php index 65501b07474..358f3df8e16 100644 --- a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php +++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php @@ -72,29 +72,13 @@ trait DependencySerializationTrait { */ #[\ReturnTypeWillChange] public function __wakeup() { - // Tests in isolation potentially unserialize in the parent process. - $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 = []; - // 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 ($this->_entityStorages && (!$phpunit_bootstrap || $container->has('entity_type.manager'))) { + if ($this->_entityStorages) { /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $container->get('entity_type.manager'); foreach ($this->_entityStorages as $key => $entity_type_id) { diff --git a/core/modules/views_ui/tests/src/Kernel/ViewsUiObjectTest.php b/core/modules/views_ui/tests/src/Kernel/ViewsUiObjectTest.php new file mode 100644 index 00000000000..fae9e6d66c6 --- /dev/null +++ b/core/modules/views_ui/tests/src/Kernel/ViewsUiObjectTest.php @@ -0,0 +1,51 @@ +getMockBuilder(ViewExecutable::class) + ->disableOriginalConstructor() + ->setConstructorArgs([$storage]) + ->getMock(); + $storage->set('executable', $executable); + + $view_ui = new ViewUI($storage); + + // Make sure the executable is returned before serializing. + $this->assertInstanceOf(ViewExecutable::class, $view_ui->getExecutable()); + + $serialized = serialize($view_ui); + + // Make sure the ViewExecutable class is not found in the serialized string. + $this->assertStringNotContainsString('"Drupal\views\ViewExecutable"', $serialized); + + $unserialized = unserialize($serialized); + $this->assertInstanceOf(ViewUI::class, $unserialized); + // Ensure serialization magic repopulated the object with the executable. + $this->assertInstanceOf(ViewExecutable::class, $unserialized->getExecutable()); + } + +} diff --git a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php index d98a31dd04c..8889127d0ef 100644 --- a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php +++ b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\views_ui\Unit; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\TempStore\Lock; use Drupal\Tests\UnitTestCase; -use Drupal\views\Entity\View; use Drupal\views_ui\ViewUI; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,7 +19,7 @@ class ViewUIObjectTest extends UnitTestCase { /** * Tests entity method decoration. */ - public function testEntityDecoration() { + public function testEntityDecoration(): void { $method_args = []; $method_args['setOriginalId'] = [12]; $method_args['setStatus'] = [TRUE]; @@ -74,8 +73,10 @@ class ViewUIObjectTest extends UnitTestCase { /** * Tests the isLocked method. + * + * @runInSeparateProcess */ - public function testIsLocked() { + public function testIsLocked(): void { $storage = $this->getMockBuilder('Drupal\views\Entity\View') ->setConstructorArgs([[], 'view']) ->getMock(); @@ -108,33 +109,8 @@ class ViewUIObjectTest extends UnitTestCase { $view_ui->setLock($lock); $this->assertFalse($view_ui->isLocked()); - $view_ui->unsetLock(NULL); + $view_ui->unsetLock(); $this->assertFalse($view_ui->isLocked()); } - /** - * Tests serialization of the ViewUI object. - */ - public function testSerialization() { - $storage = new View([], 'view'); - $executable = $this->getMockBuilder('Drupal\views\ViewExecutable') - ->disableOriginalConstructor() - ->setConstructorArgs([$storage]) - ->getMock(); - $storage->set('executable', $executable); - - $view_ui = new ViewUI($storage); - - // Make sure the executable is returned before serializing. - $this->assertInstanceOf('Drupal\views\ViewExecutable', $view_ui->getExecutable()); - - $serialized = serialize($view_ui); - - // Make sure the ViewExecutable class is not found in the serialized string. - $this->assertStringNotContainsString('"Drupal\views\ViewExecutable"', $serialized); - - $unserialized = unserialize($serialized); - $this->assertInstanceOf('Drupal\views_ui\ViewUI', $unserialized); - } - }