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