SerializableTempstoreTest.php in Chaos Tool Suite (ctools) 8.3
File
tests/src/Kernel/SerializableTempstoreTest.php
View source
<?php
namespace Drupal\Tests\ctools\Kernel;
use Drupal\ctools\SerializableTempstore;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
class SerializableTempstoreTest extends KernelTestBase {
protected static $modules = [
'ctools',
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'key_value_expire',
]);
}
public function testSerializableTempStore() {
$store = $this->container
->get('ctools.serializable.tempstore.factory')
->get('foobar');
$request = $this
->prophesize(Request::class);
$request
->willImplement('\\Serializable');
$request
->serialize()
->willThrow(new \LogicException('Not cool, bruh!'));
$this->container
->get('request_stack')
->push($request
->reveal());
$this
->assertInstanceOf(SerializableTempstore::class, $store);
$store = serialize($store);
$this
->assertSame('string', gettype($store));
$this
->assertNotEmpty($store, 'The tempstore was serialized.');
$store = unserialize($store);
$this
->assertInstanceOf(SerializableTempstore::class, $store, 'The tempstore was unserialized.');
$reflector = new \ReflectionClass($store);
$property = $reflector
->getProperty('requestStack');
$property
->setAccessible(TRUE);
$request_stack = $property
->getValue($store);
$this
->assertSame($this->container
->get('request_stack'), $request_stack, 'The request stack was pulled from the container during unserialization.');
$this
->assertSame($request
->reveal(), $request_stack
->pop());
}
}