Completed
Pull Request — master (#6865)
by Damian
07:13
created

CacheTest::testApcuCacheFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Core\Tests\Cache;
4
5
use Psr\SimpleCache\CacheInterface;
6
use SilverStripe\Core\Cache\ApcuCacheFactory;
7
use SilverStripe\Core\Cache\MemcachedCacheFactory;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Core\Test\Cache\CacheTest\MockCache;
11
use SilverStripe\Dev\SapphireTest;
12
use Symfony\Component\Cache\Simple\ApcuCache;
13
use Symfony\Component\Cache\Simple\MemcachedCache;
14
15
class CacheTest extends SapphireTest
16
{
17
    protected function setUp()
18
    {
19
        parent::setUp();
20
21
        Config::modify()
22
            ->set(
23
                Injector::class,
24
                ApcuCacheFactory::class,
25
                [
26
                    'constructor' => [ 'version' => 4400 ]
27
                ]
28
            )
29
            ->set(
30
                Injector::class,
31
                CacheInterface::class . '.TestApcuCache',
32
                [
33
                    'factory' => ApcuCacheFactory::class,
34
                    'constructor' => [
35
                        'namespace' => 'TestApcuCache',
36
                        'defaultLifetime' => 2600,
37
                    ],
38
                ]
39
            )
40
            ->set(
41
                Injector::class,
42
                CacheInterface::class . '.TestMemcache',
43
                [
44
                    'factory' => MemcachedCacheFactory::class,
45
                    'constructor' => [
46
                        'namespace' => 'TestMemCache',
47
                        'defaultLifetime' => 5600,
48
                    ],
49
                ]
50
            )
51
            ->set(Injector::class, ApcuCache::class, MockCache::class)
52
            ->set(Injector::class, MemcachedCache::class, MockCache::class);
53
    }
54
55
    public function testApcuCacheFactory()
56
    {
57
        $cache = Injector::inst()->get(CacheInterface::class .'.TestApcuCache');
58
        $this->assertInstanceOf(
59
            MockCache::class,
60
            $cache
61
        );
62
        $this->assertEquals(
63
            [
64
                'TestApcuCache_'.md5(BASE_PATH),
65
                2600,
66
                4400
67
            ],
68
            $cache->getArgs()
69
        );
70
    }
71
72
    public function testMemCacheFactory()
73
    {
74
        $cache = Injector::inst()->get(CacheInterface::class .'.TestMemcache');
75
        $this->assertInstanceOf(
76
            MockCache::class,
77
            $cache
78
        );
79
        $this->assertEquals(
80
            [
81
                null,
82
                'TestMemCache_'.md5(BASE_PATH),
83
                5600
84
            ],
85
            $cache->getArgs()
86
        );
87
    }
88
}
89