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

51 lines
1.2 KiB
PHP
Raw Normal View History

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;
use Shlinkio\Shlink\Core\Options\AppOptions;
2016-05-01 18:54:56 +03:00
use Zend\ServiceManager\ServiceManager;
use function putenv;
2016-05-01 18:54:56 +03:00
class CacheFactoryTest extends TestCase
{
/** @var CacheFactory */
private $factory;
/** @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();
$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 */
public function productionReturnsApcAdapter(): void
2016-05-01 18:54:56 +03:00
{
putenv('APP_ENV=pro');
$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 */
public function developmentReturnsArrayAdapter(): void
2016-05-01 18:54:56 +03:00
{
putenv('APP_ENV=dev');
$instance = ($this->factory)($this->sm, '');
$this->assertInstanceOf(ArrayCache::class, $instance);
}
2016-05-01 18:54:56 +03:00
}