silverstripe-framework/tests/php/Core/Cache/CacheTest.php

79 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Core\Tests\Cache;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Core\Cache\ApcuCacheFactory;
use SilverStripe\Core\Cache\MemcachedCacheFactory;
use SilverStripe\Core\Injector\Injector;
2017-09-27 17:43:01 +02:00
use SilverStripe\Core\Tests\Cache\CacheTest\MockCache;
use SilverStripe\Dev\SapphireTest;
use Symfony\Component\Cache\Simple\ApcuCache;
use Symfony\Component\Cache\Simple\MemcachedCache;
class CacheTest extends SapphireTest
{
protected function setUp(): void
{
parent::setUp();
Injector::inst()
->load([
ApcuCacheFactory::class => [
'constructor' => [ 'version' => 'ss40test' ]
],
MemcachedCacheFactory::class => MemcachedCacheFactory::class,
CacheInterface::class . '.TestApcuCache' => [
'factory' => ApcuCacheFactory::class,
'constructor' => [
'namespace' => 'TestApcuCache',
'defaultLifetime' => 2600,
],
],
CacheInterface::class . '.TestMemcache' => [
'factory' => MemcachedCacheFactory::class,
'constructor' => [
'namespace' => 'TestMemCache',
'defaultLifetime' => 5600,
],
],
ApcuCache::class => MockCache::class,
MemcachedCache::class => MockCache::class,
]);
}
public function testApcuCacheFactory()
{
2018-01-16 19:39:30 +01:00
$cache = Injector::inst()->get(CacheInterface::class . '.TestApcuCache');
$this->assertInstanceOf(
MockCache::class,
$cache
);
$this->assertEquals(
[
2018-01-16 19:39:30 +01:00
'TestApcuCache_' . md5(BASE_PATH),
2600,
'ss40test'
],
$cache->getArgs()
);
}
public function testMemCacheFactory()
{
2018-01-16 19:39:30 +01:00
$cache = Injector::inst()->get(CacheInterface::class . '.TestMemcache');
$this->assertInstanceOf(
MockCache::class,
$cache
);
$this->assertEquals(
[
null,
2018-01-16 19:39:30 +01:00
'TestMemCache_' . md5(BASE_PATH),
5600
],
$cache->getArgs()
);
}
}