Newer
Older
catch
committed
<?php
/**
* @file
* Contains \Drupal\config\Tests\Storage\CachedStorageTest.
catch
committed
*/
namespace Drupal\config\Tests\Storage;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
catch
committed
/**
* Tests CachedStorage operations.
*
* @group config
catch
committed
*/
class CachedStorageTest extends ConfigStorageTestBase {
/**
* The cache backend the cached storage is using.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* The file storage the cached storage is using.
*
* @var \Drupal\Core\Config\FileStorage
*/
Angie Byron
committed
protected $fileStorage;
catch
committed
Alex Pott
committed
protected function setUp() {
catch
committed
parent::setUp();
// Create a directory.
$dir = $this->publicFilesDirectory . '/config';
mkdir($dir);
$this->fileStorage = new FileStorage($dir);
Angie Byron
committed
$this->storage = new CachedStorage($this->fileStorage, \Drupal::service('cache.config'));
catch
committed
$this->cache = \Drupal::service('cache_factory')->get('config');
// ::listAll() verifications require other configuration data to exist.
$this->storage->write('system.performance', array());
}
/**
* {@inheritdoc}
*/
public function testInvalidStorage() {
// No-op as this test does not make sense.
}
/**
* {@inheritdoc}
*/
protected function read($name) {
$data = $this->cache->get($name);
// Cache misses fall through to the underlying storage.
Angie Byron
committed
return $data ? $data->data : $this->fileStorage->read($name);
catch
committed
}
/**
* {@inheritdoc}
*/
protected function insert($name, $data) {
Angie Byron
committed
$this->fileStorage->write($name, $data);
catch
committed
$this->cache->set($name, $data);
}
/**
* {@inheritdoc}
*/
protected function update($name, $data) {
Angie Byron
committed
$this->fileStorage->write($name, $data);
catch
committed
$this->cache->set($name, $data);
}
/**
* {@inheritdoc}
*/
protected function delete($name) {
$this->cache->delete($name);
Angie Byron
committed
unlink($this->fileStorage->getFilePath($name));
catch
committed
}
/**
* {@inheritdoc}
*/
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
// Use the regular database cache backend to aid testing.
$container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory')
catch
committed
->addArgument(new Reference('database'))
->addArgument(new Reference('cache_tags.invalidator.checksum'));