shlink/module/Common/test/Cache/CacheFactoryTest.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2016-05-01 17:54:56 +02:00
<?php
2017-10-12 10:13:20 +02:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\Cache;
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;
use Shlinkio\Shlink\Common\Cache\CacheFactory;
use Shlinkio\Shlink\Core\Options\AppOptions;
2016-05-01 17:54:56 +02:00
use Zend\ServiceManager\ServiceManager;
use function putenv;
2016-05-01 17:54:56 +02:00
class CacheFactoryTest extends TestCase
{
/** @var CacheFactory */
private $factory;
/** @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();
$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 */
public function productionReturnsApcAdapter(): void
2016-05-01 17:54:56 +02:00
{
putenv('APP_ENV=pro');
$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 */
public function developmentReturnsArrayAdapter(): void
2016-05-01 17:54:56 +02:00
{
putenv('APP_ENV=dev');
$instance = ($this->factory)($this->sm, '');
$this->assertInstanceOf(ArrayCache::class, $instance);
}
2016-05-01 17:54:56 +02:00
}