2017-05-02 23:54:14 +02:00
|
|
|
<?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;
|
2017-05-02 23:54:14 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use Symfony\Component\Cache\Simple\ApcuCache;
|
|
|
|
use Symfony\Component\Cache\Simple\MemcachedCache;
|
|
|
|
|
|
|
|
class CacheTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-05-11 07:38:29 +02:00
|
|
|
Injector::inst()
|
|
|
|
->load([
|
|
|
|
ApcuCacheFactory::class => [
|
|
|
|
'constructor' => [ 'version' => 'ss40test' ]
|
|
|
|
],
|
|
|
|
MemcachedCacheFactory::class => MemcachedCacheFactory::class,
|
|
|
|
CacheInterface::class . '.TestApcuCache' => [
|
2017-05-02 23:54:14 +02:00
|
|
|
'factory' => ApcuCacheFactory::class,
|
|
|
|
'constructor' => [
|
|
|
|
'namespace' => 'TestApcuCache',
|
|
|
|
'defaultLifetime' => 2600,
|
|
|
|
],
|
2017-05-11 07:38:29 +02:00
|
|
|
],
|
|
|
|
CacheInterface::class . '.TestMemcache' => [
|
2017-05-02 23:54:14 +02:00
|
|
|
'factory' => MemcachedCacheFactory::class,
|
|
|
|
'constructor' => [
|
|
|
|
'namespace' => 'TestMemCache',
|
|
|
|
'defaultLifetime' => 5600,
|
|
|
|
],
|
2017-05-11 07:38:29 +02:00
|
|
|
],
|
|
|
|
ApcuCache::class => MockCache::class,
|
|
|
|
MemcachedCache::class => MockCache::class,
|
|
|
|
]);
|
2017-05-02 23:54:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testApcuCacheFactory()
|
|
|
|
{
|
2018-01-16 19:39:30 +01:00
|
|
|
$cache = Injector::inst()->get(CacheInterface::class . '.TestApcuCache');
|
2017-05-02 23:54:14 +02:00
|
|
|
$this->assertInstanceOf(
|
|
|
|
MockCache::class,
|
|
|
|
$cache
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
2018-01-16 19:39:30 +01:00
|
|
|
'TestApcuCache_' . md5(BASE_PATH),
|
2017-05-02 23:54:14 +02:00
|
|
|
2600,
|
2017-05-11 07:38:29 +02:00
|
|
|
'ss40test'
|
2017-05-02 23:54:14 +02:00
|
|
|
],
|
|
|
|
$cache->getArgs()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMemCacheFactory()
|
|
|
|
{
|
2018-01-16 19:39:30 +01:00
|
|
|
$cache = Injector::inst()->get(CacheInterface::class . '.TestMemcache');
|
2017-05-02 23:54:14 +02:00
|
|
|
$this->assertInstanceOf(
|
|
|
|
MockCache::class,
|
|
|
|
$cache
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
null,
|
2018-01-16 19:39:30 +01:00
|
|
|
'TestMemCache_' . md5(BASE_PATH),
|
2017-05-02 23:54:14 +02:00
|
|
|
5600
|
|
|
|
],
|
|
|
|
$cache->getArgs()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|