function SharedTempStoreTest::testSerialization

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testSerialization()
  2. 8.9.x core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testSerialization()
  3. 11.x core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testSerialization()

Tests the serialization of a shared temp store.

File

core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php, line 353

Class

SharedTempStoreTest
@coversDefaultClass \Drupal\Core\TempStore\SharedTempStore @group TempStore

Namespace

Drupal\Tests\Core\TempStore

Code

public function testSerialization() : void {
    // Add an unserializable request to the request stack. If the tempstore
    // didn't use DependencySerializationTrait, an exception would be thrown
    // when we try to serialize the tempstore.
    $unserializable_request = new UnserializableRequest();
    $this->requestStack
        ->push($unserializable_request);
    $container = TestKernel::setContainerWithKernel();
    $container->set('request_stack', $this->requestStack);
    \Drupal::setContainer($container);
    $store = unserialize(serialize($this->tempStore));
    $this->assertInstanceOf(SharedTempStore::class, $store);
    $reflected_request_stack = (new \ReflectionObject($store))->getProperty('requestStack');
    $request_stack = $reflected_request_stack->getValue($store);
    $this->assertEquals($this->requestStack, $request_stack);
    $this->assertSame($unserializable_request, $request_stack->pop());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.