Unverified Commit 31a25fb4 authored by alexpott's avatar alexpott

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

parent 1eaf8e63
......@@ -2,6 +2,7 @@
namespace Drupal\Core\TempStore;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -37,6 +38,8 @@
*/
class SharedTempStore {
use DependencySerializationTrait;
/**
* The key/value storage object used for this data.
*
......
......@@ -6,6 +6,7 @@
use Drupal\Tests\UnitTestCase;
use Drupal\Core\TempStore\SharedTempStore;
use Drupal\Core\TempStore\TempStoreException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -382,4 +383,32 @@ public function testDeleteIfOwner() {
$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());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment