Passed
Pull Request — master (#444)
by Alejandro
08:10
created

CacheFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
c 0
b 0
f 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDownAfterClass() 0 3 1
A developmentReturnsArrayAdapter() 0 5 1
A setUp() 0 5 1
A productionReturnsApcAdapter() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Cache;
5
6
use Doctrine\Common\Cache\ApcuCache;
7
use Doctrine\Common\Cache\ArrayCache;
8
use PHPUnit\Framework\TestCase;
9
use Shlinkio\Shlink\Common\Cache\CacheFactory;
10
use Shlinkio\Shlink\Core\Options\AppOptions;
11
use Zend\ServiceManager\ServiceManager;
12
13
use function putenv;
14
15
class CacheFactoryTest extends TestCase
16
{
17
    /** @var CacheFactory */
18
    private $factory;
19
    /** @var ServiceManager */
20
    private $sm;
21
22
    public function setUp(): void
23
    {
24
        $this->factory = new CacheFactory();
25
        $this->sm = new ServiceManager(['services' => [
26
            AppOptions::class => new AppOptions(),
27
        ]]);
28
    }
29
30
    public static function tearDownAfterClass(): void
31
    {
32
        putenv('APP_ENV');
33
    }
34
35
    /** @test */
36
    public function productionReturnsApcAdapter(): void
37
    {
38
        putenv('APP_ENV=pro');
39
        $instance = ($this->factory)($this->sm, '');
40
        $this->assertInstanceOf(ApcuCache::class, $instance);
41
    }
42
43
    /** @test */
44
    public function developmentReturnsArrayAdapter(): void
45
    {
46
        putenv('APP_ENV=dev');
47
        $instance = ($this->factory)($this->sm, '');
48
        $this->assertInstanceOf(ArrayCache::class, $instance);
49
    }
50
}
51