mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved CacheFactory so that adapter can be set in config
This commit is contained in:
@@ -3,6 +3,7 @@ namespace ShlinkioTest\Shlink\Common\Factory;
|
||||
|
||||
use Doctrine\Common\Cache\ApcuCache;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Cache\FilesystemCache;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Shlinkio\Shlink\Common\Factory\CacheFactory;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
@@ -30,7 +31,7 @@ class CacheFactoryTest extends TestCase
|
||||
public function productionReturnsApcAdapter()
|
||||
{
|
||||
putenv('APP_ENV=pro');
|
||||
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
||||
$instance = $this->factory->__invoke($this->createSM(), '');
|
||||
$this->assertInstanceOf(ApcuCache::class, $instance);
|
||||
}
|
||||
|
||||
@@ -40,7 +41,36 @@ class CacheFactoryTest extends TestCase
|
||||
public function developmentReturnsArrayAdapter()
|
||||
{
|
||||
putenv('APP_ENV=dev');
|
||||
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
||||
$instance = $this->factory->__invoke($this->createSM(), '');
|
||||
$this->assertInstanceOf(ArrayCache::class, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function adapterDefinedInConfigIgnoresEnvironment()
|
||||
{
|
||||
putenv('APP_ENV=pro');
|
||||
$instance = $this->factory->__invoke($this->createSM(ArrayCache::class), '');
|
||||
$this->assertInstanceOf(ArrayCache::class, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidAdapterDefinedInConfigFallbacksToEnvironment()
|
||||
{
|
||||
putenv('APP_ENV=pro');
|
||||
$instance = $this->factory->__invoke($this->createSM(FilesystemCache::class), '');
|
||||
$this->assertInstanceOf(ApcuCache::class, $instance);
|
||||
}
|
||||
|
||||
private function createSM($cacheAdapter = null)
|
||||
{
|
||||
return new ServiceManager(['services' => [
|
||||
'config' => isset($cacheAdapter) ? [
|
||||
'cache' => ['adapter' => $cacheAdapter],
|
||||
] : [],
|
||||
]]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user