2016-05-01 17:54:56 +02:00
|
|
|
<?php
|
2017-10-12 10:13:20 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-19 17:38:41 +02:00
|
|
|
namespace ShlinkioTest\Shlink\Common\Factory;
|
2016-05-01 17:54:56 +02:00
|
|
|
|
|
|
|
use Doctrine\Common\Cache\ApcuCache;
|
|
|
|
use Doctrine\Common\Cache\ArrayCache;
|
2017-03-24 20:34:18 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-19 17:38:41 +02:00
|
|
|
use Shlinkio\Shlink\Common\Factory\CacheFactory;
|
2016-08-15 23:40:49 +02:00
|
|
|
use Shlinkio\Shlink\Core\Options\AppOptions;
|
2016-05-01 17:54:56 +02:00
|
|
|
use Zend\ServiceManager\ServiceManager;
|
2019-02-26 22:56:43 +01:00
|
|
|
|
2018-10-28 08:34:02 +01:00
|
|
|
use function putenv;
|
2016-05-01 17:54:56 +02:00
|
|
|
|
|
|
|
class CacheFactoryTest extends TestCase
|
|
|
|
{
|
2018-11-20 19:30:27 +01:00
|
|
|
/** @var CacheFactory */
|
2018-11-20 19:37:22 +01:00
|
|
|
private $factory;
|
2019-04-11 22:36:50 +02:00
|
|
|
/** @var ServiceManager */
|
|
|
|
private $sm;
|
2016-05-01 17:54:56 +02:00
|
|
|
|
2019-02-16 10:53:45 +01:00
|
|
|
public function setUp(): void
|
2016-05-01 17:54:56 +02:00
|
|
|
{
|
|
|
|
$this->factory = new CacheFactory();
|
2019-04-11 22:36:50 +02:00
|
|
|
$this->sm = new ServiceManager(['services' => [
|
|
|
|
AppOptions::class => new AppOptions(),
|
|
|
|
]]);
|
2016-05-01 17:54:56 +02:00
|
|
|
}
|
|
|
|
|
2019-02-16 10:53:45 +01:00
|
|
|
public static function tearDownAfterClass(): void
|
2016-05-01 17:54:56 +02:00
|
|
|
{
|
|
|
|
putenv('APP_ENV');
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:28:34 +01:00
|
|
|
/** @test */
|
2019-04-11 22:36:50 +02:00
|
|
|
public function productionReturnsApcAdapter(): void
|
2016-05-01 17:54:56 +02:00
|
|
|
{
|
|
|
|
putenv('APP_ENV=pro');
|
2019-04-11 22:36:50 +02:00
|
|
|
$instance = ($this->factory)($this->sm, '');
|
2016-05-01 17:54:56 +02:00
|
|
|
$this->assertInstanceOf(ApcuCache::class, $instance);
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:28:34 +01:00
|
|
|
/** @test */
|
2019-04-11 22:36:50 +02:00
|
|
|
public function developmentReturnsArrayAdapter(): void
|
2016-05-01 17:54:56 +02:00
|
|
|
{
|
|
|
|
putenv('APP_ENV=dev');
|
2019-04-11 22:36:50 +02:00
|
|
|
$instance = ($this->factory)($this->sm, '');
|
2016-08-01 20:16:13 +02:00
|
|
|
$this->assertInstanceOf(ArrayCache::class, $instance);
|
|
|
|
}
|
2016-05-01 17:54:56 +02:00
|
|
|
}
|