3 namespace Drupal\Tests\ctools\Kernel;
5 use Drupal\ctools\SerializableTempstore;
6 use Drupal\KernelTests\KernelTestBase;
7 use Symfony\Component\HttpFoundation\Request;
10 * Tests the serializable tempstore service.
14 class SerializableTempstoreTest extends KernelTestBase {
19 public static $modules = ['ctools', 'system', 'user'];
24 protected function setUp() {
26 $this->installSchema('system', ['key_value_expire']);
30 * Tests serializing a serializable temp store object.
32 public function testSerializableTempStore() {
33 $store = $this->container
34 ->get('ctools.serializable.tempstore.factory')
37 // Add an unserializable request to the request stack. If the tempstore
38 // didn't use DependencySerializationTrait, the exception would be thrown
39 // when we try to serialize the tempstore.
40 $request = $this->prophesize(Request::class);
41 $request->willImplement('\Serializable');
42 $request->serialize()->willThrow(new \LogicException('Not cool, bruh!'));
43 $this->container->get('request_stack')->push($request->reveal());
45 $this->assertInstanceOf(SerializableTempstore::class, $store);
46 /** @var SerializableTempstore $store */
48 $store = serialize($store);
49 $this->assertInternalType('string', $store);
50 $this->assertNotEmpty($store, 'The tempstore was serialized.');
52 $store = unserialize($store);
53 $this->assertInstanceOf(SerializableTempstore::class, $store, 'The tempstore was unserialized.');
55 $request_stack = $this->getObjectAttribute($store, 'requestStack');
57 $this->container->get('request_stack'),
59 'The request stack was pulled from the container during unserialization.'
61 $this->assertSame($request->reveal(), $request_stack->pop());