Skip to content
Snippets Groups Projects
Unverified Commit 31a25fb4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3049437 by mfb, amateescu: SharedTempStore not serializable on PHP 7.3

parent 1eaf8e63
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
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Core\TempStore; namespace Drupal\Core\TempStore;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
...@@ -37,6 +38,8 @@ ...@@ -37,6 +38,8 @@
*/ */
class SharedTempStore { class SharedTempStore {
use DependencySerializationTrait;
/** /**
* The key/value storage object used for this data. * The key/value storage object used for this data.
* *
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\Core\TempStore\SharedTempStore; use Drupal\Core\TempStore\SharedTempStore;
use Drupal\Core\TempStore\TempStoreException; use Drupal\Core\TempStore\TempStoreException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
...@@ -382,4 +383,32 @@ public function testDeleteIfOwner() { ...@@ -382,4 +383,32 @@ public function testDeleteIfOwner() {
$this->assertFalse($this->tempStore->deleteIfOwner('test_3')); $this->assertFalse($this->tempStore->deleteIfOwner('test_3'));
} }
/**
* Tests the serialization of a shared temp store.
*/
public function testSerialization() {
// Add an unserializable request to the request stack. If the tempstore
// didn't use DependencySerializationTrait, the exception would be thrown
// when we try to serialize the tempstore.
$request = $this->prophesize(Request::class);
$request->willImplement('\Serializable');
$request->serialize()->willThrow(new \LogicException('Oops!'));
$unserializable_request = $request->reveal();
$this->requestStack->push($unserializable_request);
$this->requestStack->_serviceId = 'request_stack';
$container = $this->prophesize(ContainerInterface::class);
$container->get('request_stack')->willReturn($this->requestStack);
$container->has('request_stack')->willReturn(TRUE);
\Drupal::setContainer($container->reveal());
$store = unserialize(serialize($this->tempStore));
$this->assertInstanceOf(SharedTempStore::class, $store);
$request_stack = $this->getObjectAttribute($store, 'requestStack');
$this->assertEquals($this->requestStack, $request_stack);
$this->assertSame($unserializable_request, $request_stack->pop());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment