Loading core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php +1 −17 Original line number Diff line number Diff line Loading @@ -72,29 +72,13 @@ public function __sleep() { */ #[\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) { Loading core/modules/views_ui/tests/src/Kernel/ViewsUiObjectTest.php 0 → 100644 +51 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\views_ui\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\views\Entity\View; use Drupal\views\ViewExecutable; use Drupal\views_ui\ViewUI; /** * @group views_ui */ class ViewsUiObjectTest extends KernelTestBase { /** * Modules to enable. * * @var array */ protected static $modules = ['views', 'views_ui']; /** * Tests serialization of the ViewUI object. */ public function testSerialization(): void { $storage = new View([], 'view'); $executable = $this->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()); } } core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php +5 −29 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ 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; Loading @@ -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]; Loading Loading @@ -74,8 +73,10 @@ public function testEntityDecoration() { /** * Tests the isLocked method. * * @runInSeparateProcess */ public function testIsLocked() { public function testIsLocked(): void { $storage = $this->getMockBuilder('Drupal\views\Entity\View') ->setConstructorArgs([[], 'view']) ->getMock(); Loading Loading @@ -108,33 +109,8 @@ public function testIsLocked() { $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); } } Loading
core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php +1 −17 Original line number Diff line number Diff line Loading @@ -72,29 +72,13 @@ public function __sleep() { */ #[\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) { Loading
core/modules/views_ui/tests/src/Kernel/ViewsUiObjectTest.php 0 → 100644 +51 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\views_ui\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\views\Entity\View; use Drupal\views\ViewExecutable; use Drupal\views_ui\ViewUI; /** * @group views_ui */ class ViewsUiObjectTest extends KernelTestBase { /** * Modules to enable. * * @var array */ protected static $modules = ['views', 'views_ui']; /** * Tests serialization of the ViewUI object. */ public function testSerialization(): void { $storage = new View([], 'view'); $executable = $this->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()); } }
core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php +5 −29 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ 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; Loading @@ -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]; Loading Loading @@ -74,8 +73,10 @@ public function testEntityDecoration() { /** * Tests the isLocked method. * * @runInSeparateProcess */ public function testIsLocked() { public function testIsLocked(): void { $storage = $this->getMockBuilder('Drupal\views\Entity\View') ->setConstructorArgs([[], 'view']) ->getMock(); Loading Loading @@ -108,33 +109,8 @@ public function testIsLocked() { $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); } }