View source
<?php
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\Core\Cache\CacheCollectorHelper;
use Symfony\Component\DependencyInjection\Reference;
class CacheCollectorTest extends KernelTestBase {
public function register(ContainerBuilder $container) {
parent::register($container);
$container
->register('cache_factory', 'Drupal\\Core\\Cache\\CacheFactory')
->addArgument(new Reference('settings'))
->addMethodCall('setContainer', [
new Reference('service_container'),
]);
$container
->register('lock', 'Drupal\\Core\\Lock\\DatabaseLockBackend')
->addArgument(new Reference('database'));
}
public function testCacheCollector($cid, $key, $value) {
$collector = new CacheCollectorHelper($cid, $this->container
->get('cache.default'), $this->container
->get('lock'));
$this
->assertNull($collector
->get($key));
$collector
->set($key, $value);
$this
->assertEquals($value, $collector
->get($key));
$collector
->destruct();
$this
->assertEquals($value, $collector
->get($key));
}
public function providerTestInvalidCharacters() {
return [
[
'foo',
'bar',
'baz',
],
[
'éøïвβ中國書۞',
'foo',
'bar',
],
[
$this
->randomString(1024),
'foo',
'bar',
],
];
}
}