Completed
Push — fix-2494 ( 3153ee )
by Sam
07:19
created

CacheTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 37
rs 8.8571
c 0
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 View Code Duplication
    public function testApcuCacheFactory()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testMemCacheFactory()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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