mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Improved CacheFactory supporting more adapters
This commit is contained in:
@@ -4,6 +4,8 @@ namespace ShlinkioTest\Shlink\Common\Factory;
|
||||
use Doctrine\Common\Cache\ApcuCache;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Cache\FilesystemCache;
|
||||
use Doctrine\Common\Cache\MemcachedCache;
|
||||
use Doctrine\Common\Cache\RedisCache;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Shlinkio\Shlink\Common\Factory\CacheFactory;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
@@ -61,15 +63,51 @@ class CacheFactoryTest extends TestCase
|
||||
public function invalidAdapterDefinedInConfigFallbacksToEnvironment()
|
||||
{
|
||||
putenv('APP_ENV=pro');
|
||||
$instance = $this->factory->__invoke($this->createSM(FilesystemCache::class), '');
|
||||
$instance = $this->factory->__invoke($this->createSM(RedisCache::class), '');
|
||||
$this->assertInstanceOf(ApcuCache::class, $instance);
|
||||
}
|
||||
|
||||
private function createSM($cacheAdapter = null)
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function filesystemCacheAdaptersReadDirOption()
|
||||
{
|
||||
$dir = sys_get_temp_dir();
|
||||
/** @var FilesystemCache $instance */
|
||||
$instance = $this->factory->__invoke($this->createSM(FilesystemCache::class, ['dir' => $dir]), '');
|
||||
$this->assertInstanceOf(FilesystemCache::class, $instance);
|
||||
$this->assertEquals($dir, $instance->getDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function memcachedCacheAdaptersReadServersOption()
|
||||
{
|
||||
$servers = [
|
||||
[
|
||||
'host' => '1.2.3.4',
|
||||
'port' => 123
|
||||
],
|
||||
[
|
||||
'host' => '4.3.2.1',
|
||||
'port' => 321
|
||||
],
|
||||
];
|
||||
/** @var MemcachedCache $instance */
|
||||
$instance = $this->factory->__invoke($this->createSM(MemcachedCache::class, ['servers' => $servers]), '');
|
||||
$this->assertInstanceOf(MemcachedCache::class, $instance);
|
||||
$this->assertEquals($servers, $instance->getMemcached()->getServerList());
|
||||
}
|
||||
|
||||
private function createSM($cacheAdapter = null, array $options = [])
|
||||
{
|
||||
return new ServiceManager(['services' => [
|
||||
'config' => isset($cacheAdapter) ? [
|
||||
'cache' => ['adapter' => $cacheAdapter],
|
||||
'cache' => [
|
||||
'adapter' => $cacheAdapter,
|
||||
'options' => $options,
|
||||
],
|
||||
] : [],
|
||||
]]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user