diff --git a/core/core.services.yml b/core/core.services.yml index 953c7c5..cdab4ef 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -192,7 +192,7 @@ services: - [setContainer, ['@service_container']] cache.backend.database: class: Drupal\Core\Cache\DatabaseBackendFactory - arguments: ['@database', '@cache_tags.invalidator.checksum'] + arguments: ['@serialization.phpserialize', '@database', '@cache_tags.invalidator.checksum'] cache.backend.apcu: class: Drupal\Core\Cache\ApcuBackendFactory arguments: ['@app.root', '@site.path', '@cache_tags.invalidator.checksum'] @@ -201,6 +201,7 @@ services: arguments: ['@cache_tags.invalidator.checksum'] cache.backend.memory: class: Drupal\Core\Cache\MemoryBackendFactory + arguments: ['@serialization.phpserialize'] # A special cache bin that does not persist beyond the length of the request. cache.static: class: Drupal\Core\Cache\CacheBackendInterface diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index a96d183..e48fddf 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Cache; +use Drupal\Component\Serialization\SerializationInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Connection; use Drupal\Core\Database\SchemaObjectExistsException; @@ -21,6 +22,12 @@ class DatabaseBackend implements CacheBackendInterface { */ protected $bin; + /** + * The serialization class to use. + * + * @var \Drupal\Component\Serialization\SerializationInterface + */ + protected $serializer; /** * The database connection. @@ -39,6 +46,8 @@ class DatabaseBackend implements CacheBackendInterface { /** * Constructs a DatabaseBackend object. * + * @param \Drupal\Component\Serialization\SerializationInterface $serializer + * The serialization class to use. * @param \Drupal\Core\Database\Connection $connection * The database connection. * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider @@ -46,11 +55,12 @@ class DatabaseBackend implements CacheBackendInterface { * @param string $bin * The cache bin for which the object is created. */ - public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, $bin) { + public function __construct(SerializationInterface $serializer, Connection $connection, CacheTagsChecksumInterface $checksum_provider, $bin) { // All cache tables should be prefixed with 'cache_'. $bin = 'cache_' . $bin; $this->bin = $bin; + $this->serializer = $serializer; $this->connection = $connection; $this->checksumProvider = $checksum_provider; } @@ -135,7 +145,7 @@ protected function prepareItem($cache, $allow_invalid) { // Unserialize and return the cached data. if ($cache->serialized) { - $cache->data = unserialize($cache->data); + $cache->data = $this->serializer->decode($cache->data); } return $cache; @@ -208,7 +218,7 @@ protected function doSetMultiple(array $items) { ); if (!is_string($item['data'])) { - $fields['data'] = serialize($item['data']); + $fields['data'] = $this->serializer->encode($item['data']); $fields['serialized'] = 1; } else { diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php b/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php index 5cc87e9..3a0fad2 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php @@ -2,11 +2,19 @@ namespace Drupal\Core\Cache; +use Drupal\Component\Serialization\SerializationInterface; use Drupal\Core\Database\Connection; class DatabaseBackendFactory implements CacheFactoryInterface { /** + * The serialization class to use. + * + * @var \Drupal\Component\Serialization\SerializationInterface + */ + protected $serializer; + + /** * The database connection. * * @var \Drupal\Core\Database\Connection @@ -23,12 +31,15 @@ class DatabaseBackendFactory implements CacheFactoryInterface { /** * Constructs the DatabaseBackendFactory object. * + * @param \Drupal\Component\Serialization\SerializationInterface $serializer + * The serialization class to use. * @param \Drupal\Core\Database\Connection $connection * Database connection * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider * The cache tags checksum provider. */ - function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider) { + function __construct(SerializationInterface $serializer, Connection $connection, CacheTagsChecksumInterface $checksum_provider) { + $this->serializer = $serializer; $this->connection = $connection; $this->checksumProvider = $checksum_provider; } @@ -43,7 +54,7 @@ function __construct(Connection $connection, CacheTagsChecksumInterface $checksu * The cache backend object for the specified cache bin. */ function get($bin) { - return new DatabaseBackend($this->connection, $this->checksumProvider, $bin); + return new DatabaseBackend($this->serializer, $this->connection, $this->checksumProvider, $bin); } } diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index c517fb4..292474b 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -1,6 +1,7 @@ serializer = $serializer; + } + + /** * {@inheritdoc} */ public function get($cid, $allow_invalid = FALSE) { @@ -73,11 +91,11 @@ protected function prepareItem($cache, $allow_invalid) { } // The object passed into this function is the one stored in $this->cache. // We must clone it as part of the preparation step so that the actual - // cache object is not affected by the unserialize() call or other - // manipulations of the returned object. + // cache object is not affected by the decode() call or other manipulations + // of the returned object. $prepared = clone $cache; - $prepared->data = unserialize($prepared->data); + $prepared->data = $this->serializer->decode($prepared->data); // Check expire time. $prepared->valid = $prepared->expire == Cache::PERMANENT || $prepared->expire >= $this->getRequestTime(); @@ -99,7 +117,7 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array sort($tags); $this->cache[$cid] = (object) array( 'cid' => $cid, - 'data' => serialize($data), + 'data' => $this->serializer->encode($data), 'created' => $this->getRequestTime(), 'expire' => $expire, 'tags' => $tags, diff --git a/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php index 4457e59..de2d561 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php @@ -2,9 +2,18 @@ namespace Drupal\Core\Cache; +use Drupal\Component\Serialization\SerializationInterface; + class MemoryBackendFactory implements CacheFactoryInterface { /** + * The serialization class to use. + * + * @var \Drupal\Component\Serialization\SerializationInterface + */ + protected $serializer; + + /** * Instantiated memory cache bins. * * @var \Drupal\Core\Cache\MemoryBackend[] @@ -12,11 +21,21 @@ class MemoryBackendFactory implements CacheFactoryInterface { protected $bins = array(); /** + * Constructs the MemoryBackendFactory object. + * + * @param \Drupal\Component\Serialization\SerializationInterface $serializer + * The serialization class to use. + */ + function __construct(SerializationInterface $serializer) { + $this->serializer = $serializer; + } + + /** * {@inheritdoc} */ function get($bin) { if (!isset($this->bins[$bin])) { - $this->bins[$bin] = new MemoryBackend(); + $this->bins[$bin] = new MemoryBackend($this->serializer); } return $this->bins[$bin]; } diff --git a/core/lib/Drupal/Core/Config/StorageComparer.php b/core/lib/Drupal/Core/Config/StorageComparer.php index bf071de..34ef867 100644 --- a/core/lib/Drupal/Core/Config/StorageComparer.php +++ b/core/lib/Drupal/Core/Config/StorageComparer.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Config; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Config\Entity\ConfigDependencyManager; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -99,14 +100,17 @@ class StorageComparer implements StorageComparerInterface { * The configuration manager. */ public function __construct(StorageInterface $source_storage, StorageInterface $target_storage, ConfigManagerInterface $config_manager) { + // @todo All these direct object initializations are bypassing the service + // configurations. That has to be fixed. + $php_serialize = new PhpSerialize(); // Wrap the storages in a static cache so that multiple reads of the same // raw configuration object are not costly. - $this->sourceCacheStorage = new MemoryBackend(); + $this->sourceCacheStorage = new MemoryBackend($php_serialize); $this->sourceStorage = new CachedStorage( $source_storage, $this->sourceCacheStorage ); - $this->targetCacheStorage = new MemoryBackend(); + $this->targetCacheStorage = new MemoryBackend($php_serialize); $this->targetStorage = new CachedStorage( $target_storage, $this->targetCacheStorage diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 274a3fa..b6f30c2 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -77,12 +77,15 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { ], 'cache.container' => [ 'class' => 'Drupal\Core\Cache\DatabaseBackend', - 'arguments' => ['@database', '@cache_tags_provider.container', 'container'], + 'arguments' => ['@serialization.phpserialize', '@database', '@cache_tags_provider.container', 'container'], ], 'cache_tags_provider.container' => [ 'class' => 'Drupal\Core\Cache\DatabaseCacheTagsChecksum', 'arguments' => ['@database'], ], + 'serialization.phpserialize' => [ + 'class' => 'Drupal\Component\Serialization\PhpSerialize', + ], ], ]; diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php index 1ace991..05e8d3d 100644 --- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php +++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php @@ -28,9 +28,11 @@ public function register(ContainerBuilder $container) { // Replace services with in-memory implementations. $definition = $container->getDefinition('cache_factory'); $definition->setClass('Drupal\Core\Cache\MemoryBackendFactory'); - $definition->setArguments(array()); + $definition->setArguments([new Reference('serialization.phpserialize')]); $definition->setMethodCalls(array()); $container + ->register('serialization.phpserialize', 'Drupal\Component\Serialization\PhpSerialize'); + $container ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'); $container ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory'); diff --git a/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php b/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php index 42d7a36..da20c8a 100644 --- a/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php +++ b/core/modules/hal/tests/src/Kernel/FileNormalizeTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\hal\Kernel; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\MemoryBackend; use Drupal\file\Entity\File; use Drupal\hal\Encoder\JsonEncoder; @@ -35,7 +36,7 @@ protected function setUp() { $this->installEntitySchema('file'); $entity_manager = \Drupal::entityManager(); - $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend(), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'), \Drupal::service('entity_type.bundle.info')), new RelationLinkManager(new MemoryBackend(), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'))); + $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend(new PhpSerialize()), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'), \Drupal::service('entity_type.bundle.info')), new RelationLinkManager(new MemoryBackend(), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'))); // Set up the mock serializer. $normalizers = array( diff --git a/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php b/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php index 5867476..85d76f7 100644 --- a/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php +++ b/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\hal\Kernel; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\MemoryBackend; use Drupal\field\Entity\FieldConfig; use Drupal\hal\Encoder\JsonEncoder; @@ -131,7 +132,8 @@ protected function setUp() { ])->save(); $entity_manager = \Drupal::entityManager(); - $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend(), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'), \Drupal::service('entity_type.bundle.info')), new RelationLinkManager(new MemoryBackend(), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'))); + $php_serialize = new PhpSerialize(); + $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend($php_serialize), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'), \Drupal::service('entity_type.bundle.info')), new RelationLinkManager(new MemoryBackend($php_serialize), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'))); $chain_resolver = new ChainEntityResolver(array(new UuidResolver($entity_manager), new TargetIdResolver())); diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 0b5792f..2f7a845 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -313,7 +313,10 @@ public function containerBuild(ContainerBuilder $container) { $this->container->setParameter('language.default_values', $this->defaultLanguageData()); $container->register('lock', 'Drupal\Core\Lock\NullLockBackend'); - $container->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory'); + $container->register('serialization.phpserialize', 'Drupal\Component\Serialization\PhpSerialize'); + $container + ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory') + ->addArgument(new Reference('serialization.phpserialize')); $container ->register('config.storage', 'Drupal\Core\Config\DatabaseStorage') diff --git a/core/modules/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php index ff20f5e..3207e89 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php @@ -90,6 +90,7 @@ class: $class # Swap out a core service. cache.backend.database: class: Drupal\Core\Cache\MemoryBackendFactory + arguments: ['@serialization.phpserialize'] EOD; file_put_contents($this->siteDirectory . '/testing.services.yml', $yaml); diff --git a/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php b/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php index 72c0de9..3692acb 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php @@ -17,9 +17,9 @@ protected function createCacheBackend($bin) { // We need to create some various backends in the chain. $chain - ->appendBackend(new MemoryBackend()) - ->prependBackend(new MemoryBackend()) - ->appendBackend(new MemoryBackend()); + ->appendBackend(new MemoryBackend(\Drupal::service('serialization.phpserialize'))) + ->prependBackend(new MemoryBackend(\Drupal::service('serialization.phpserialize'))) + ->appendBackend(new MemoryBackend(\Drupal::service('serialization.phpserialize'))); \Drupal::service('cache_tags.invalidator')->addInvalidator($chain); diff --git a/core/tests/Drupal/KernelTests/Core/Cache/ChainedFastBackendTest.php b/core/tests/Drupal/KernelTests/Core/Cache/ChainedFastBackendTest.php index 3021b04..f5f69b1 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/ChainedFastBackendTest.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/ChainedFastBackendTest.php @@ -20,7 +20,7 @@ class ChainedFastBackendTest extends GenericCacheBackendUnitTestBase { * A new ChainedFastBackend object. */ protected function createCacheBackend($bin) { - $consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum'), $bin); + $consistent_backend = new DatabaseBackend(\Drupal::service('serialization.phpserialize'), \Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum'), $bin); $fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum')); $backend = new ChainedFastBackend($consistent_backend, $fast_backend, $bin); // Explicitly register the cache bin as it can not work through the diff --git a/core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php b/core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php index fd1c942..5b3e6f7 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/DatabaseBackendTest.php @@ -25,7 +25,7 @@ class DatabaseBackendTest extends GenericCacheBackendUnitTestBase { * A new DatabaseBackend object. */ protected function createCacheBackend($bin) { - return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags.invalidator.checksum'), $bin); + return new DatabaseBackend($this->container->get('serialization.phpserialize'), $this->container->get('database'), $this->container->get('cache_tags.invalidator.checksum'), $bin); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Cache/MemoryBackendTest.php b/core/tests/Drupal/KernelTests/Core/Cache/MemoryBackendTest.php index 4518532..a4128ad 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/MemoryBackendTest.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/MemoryBackendTest.php @@ -18,7 +18,7 @@ class MemoryBackendTest extends GenericCacheBackendUnitTestBase { * A new MemoryBackend object. */ protected function createCacheBackend($bin) { - $backend = new MemoryBackend(); + $backend = new MemoryBackend(\Drupal::service('serialization.phpserialize')); \Drupal::service('cache_tags.invalidator')->addInvalidator($backend); return $backend; } diff --git a/core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelSiteTest.php b/core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelSiteTest.php index deea2a9..2bf753b 100644 --- a/core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelSiteTest.php +++ b/core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelSiteTest.php @@ -34,6 +34,7 @@ class: $class # Swap out a core service. cache.backend.database: class: Drupal\Core\Cache\MemoryBackendFactory + arguments: ['@serialization.phpserialize'] EOD; file_put_contents($this->siteDirectory . '/services.yml', $doc); diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php b/core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php index 3d651b1..9bbbabe 100644 --- a/core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Plugin; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\KernelTests\KernelTestBase; use Drupal\plugin_test\Plugin\TestPluginManager; @@ -42,7 +43,7 @@ protected function setUp() { // as derivatives and ReflectionFactory. $this->testPluginManager = new TestPluginManager(); $this->mockBlockManager = new MockBlockManager(); - $module_handler = new ModuleHandler(\Drupal::root(), array(), new MemoryBackend(), $this->container->get('event_dispatcher')); + $module_handler = new ModuleHandler(\Drupal::root(), array(), new MemoryBackend(new PhpSerialize()), $this->container->get('event_dispatcher')); $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler); // The expected plugin definitions within each manager. Several tests assert diff --git a/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php b/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php index 710d82f..c6dfb98 100644 --- a/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php @@ -7,6 +7,7 @@ namespace Drupal\KernelTests\Core\Routing; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; @@ -83,7 +84,7 @@ protected function setUp() { $this->fixtures = new RoutingFixtures(); $this->state = new State(new KeyValueMemoryFactory()); $this->currentPath = new CurrentPathStack(new RequestStack()); - $this->cache = new MemoryBackend(); + $this->cache = new MemoryBackend(new PhpSerialize()); $this->pathProcessor = \Drupal::service('path_processor_manager'); $this->cacheTagsInvalidator = \Drupal::service('cache_tags.invalidator'); } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index f10cb14..c9170b0 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -596,7 +596,10 @@ public function register(ContainerBuilder $container) { $container ->register('lock', 'Drupal\Core\Lock\NullLockBackend'); $container - ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory'); + ->register('serialization.phpserialize', 'Drupal\Component\Serialization\PhpSerialize'); + $container + ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory') + ->addArgument(new Reference('serialization.phpserialize')); $container ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory') // Must persist container rebuilds, or all data would vanish otherwise. diff --git a/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php b/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php index f035bde..0b0358b 100644 --- a/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Cache; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\BackendChain; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\MemoryBackend; @@ -45,10 +46,11 @@ class BackendChainImplementationUnitTest extends UnitTestCase { protected function setUp() { parent::setUp(); + $php_serialize = new PhpSerialize(); // Set up three memory backends to be used in the chain. - $this->firstBackend = new MemoryBackend(); - $this->secondBackend = new MemoryBackend(); - $this->thirdBackend = new MemoryBackend(); + $this->firstBackend = new MemoryBackend($php_serialize); + $this->secondBackend = new MemoryBackend($php_serialize); + $this->thirdBackend = new MemoryBackend($php_serialize); // Set an initial fixed dataset for all testing. The next three data // collections will test two edge cases (last backend has the data, and diff --git a/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php b/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php index 93dbd9f..b11e26c 100644 --- a/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Cache; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\ChainedFastBackend; use Drupal\Core\Cache\MemoryBackend; use Drupal\Tests\UnitTestCase; @@ -47,7 +48,7 @@ public function testGetDoesntHitConsistentBackend() { $consistent_cache->expects($this->never()) ->method('getMultiple'); - $fast_cache = new MemoryBackend(); + $fast_cache = new MemoryBackend(new PhpSerialize()); $fast_cache->set('foo', 'baz'); $chained_fast_backend = new ChainedFastBackend( diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php index a3835e1..ee89097 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\Core\Render; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\KeyValueStore\KeyValueMemoryFactory; use Drupal\Core\State\State; @@ -79,8 +80,9 @@ public function testContextBubblingCustomCacheBin() { $bin = $this->randomMachineName(); $this->setUpRequest(); - $this->memoryCache = new MemoryBackend(); - $custom_cache = new MemoryBackend(); + $php_serialize = new PhpSerialize(); + $this->memoryCache = new MemoryBackend($php_serialize); + $custom_cache = new MemoryBackend($php_serialize); $this->cacheFactory->expects($this->atLeastOnce()) ->method('get') diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php index 964898c..7bee601 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\Core\Render; +use Drupal\Component\Serialization\PhpSerialize; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\Context\ContextCacheKeys; @@ -208,7 +209,7 @@ protected function setUpUnusedCache() { * Sets up a memory-based render cache back-end. */ protected function setupMemoryCache() { - $this->memoryCache = $this->memoryCache ?: new MemoryBackend(); + $this->memoryCache = $this->memoryCache ?: new MemoryBackend(new PhpSerialize()); $this->cacheFactory->expects($this->atLeastOnce()) ->method('get')