RepositoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 20
c 2
b 0
f 1
dl 0
loc 44
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get() 0 6 1
A test_sey() 0 8 1
A test_remember() 0 17 1
A initFileStore() 0 4 1
1
<?php
2
3
namespace Nip\Cache\Tests\Stores;
4
5
use Nip\Cache\Stores\Repository;
6
use Nip\Cache\Tests\AbstractTest;
7
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
8
9
/**
10
 * Class RepositoryTest
11
 * @package Nip\Cache\Tests\Stores
12
 */
13
class RepositoryTest extends AbstractTest
14
{
15
    public function test_get()
16
    {
17
        $store = $this->initFileStore();
18
19
        $value = $store->get('test', 'default');
20
        self::assertSame('default', $value);
21
    }
22
23
    public function test_sey()
24
    {
25
        $store = $this->initFileStore();
26
        $store->set('test', 'myValue');
27
28
        $store = $this->initFileStore();
29
30
        self::assertSame('myValue', $store->get('test'));
31
    }
32
33
34
    public function test_remember()
35
    {
36
        $store = $this->initFileStore();
37
        self::assertFalse($store->has('foo'));
38
39
        $result = $store->remember('foo', 10, function () {
40
            return 'bar';
41
        });
42
        self::assertSame('bar', $result);
43
        self::assertSame('bar', $store->get('foo'));
44
45
        $result = $store->remember('foo', 10, function () {
46
            return 'bar2';
47
        });
48
49
        self::assertSame('bar', $result);
50
        self::assertSame('bar', $store->get('foo'));
51
    }
52
53
    protected function initFileStore()
54
    {
55
        $adapter = new FilesystemAdapter('', 0, CACHE_PATH);
56
        return new Repository($adapter);
57
    }
58
}
59