Completed
Push — master ( fc5eaa...427062 )
by Dan
03:22
created

CacheTest::testConstructNullStorage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Tests\Ds\Cache;
4
5
use Ds\Cache\Cache;
6
7
class CacheTest extends \PHPUnit_Framework_TestCase
8
{
9
10
    public $cache;
11
    public $storageMock;
12
13
    public function setUp()
14
    {
15
16
        $this->storageMock = $this->getMockBuilder('\Ds\Cache\Interfaces\CacheStorageInterface')
17
            ->getMock();
18
19
        $this->cache = new Cache($this->storageMock,99);
20
    }
21
22
    public function testConstructNullStorage(){
23
        $cache = new Cache();
24
        $storage = $cache->getCacheStorage();
25
        $this->assertInstanceOf('\Ds\Cache\NullStorage',$storage);
26
    }
27
28
    public function testConstructWithStorage(){
29
        $cache = new Cache($this->storageMock);
30
        $storage = $cache->getCacheStorage();
31
        $this->assertSame($this->storageMock,$storage);
32
    }
33
34 View Code Duplication
    public function testHas()
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...
35
    {
36
37
        $key = 'key';
38
39
        $this->storageMock->expects($this->once())
40
            ->method('has')
41
            ->with(
42
                $this->equalTo($key)
43
            );
44
45
        $this->cache->has($key);
46
    }
47
48 View Code Duplication
    public function testSet()
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...
49
    {
50
51
        $key = 'key';
52
        $value = 'value';
53
        $expires = 10;
54
55
        $this->storageMock->expects($this->once())
56
            ->method('set')
57
            ->with(
58
                $this->equalTo($key),
59
                $this->equalTo($value),
60
                $this->equalTo($expires)
61
            );
62
63
        $this->cache->set($key, $value, $expires);
64
    }
65
66
    public function testSetDefaultExpires()
67
    {
68
69
        $key = 'key';
70
        $value = 'value';
71
72
        $this->storageMock->expects($this->once())
73
            ->method('set')
74
            ->with(
75
                $this->equalTo($key),
76
                $this->equalTo($value),
77
                $this->equalTo(99)
78
            );
79
80
        $this->cache->set($key, $value);
81
    }
82
83
    public function testSetFromExpires()
84
    {
85
86
        $key = 'key';
87
        $value = 'value';
88
89
        $this->cache = $this->cache->setExpires(60);
90
91
        $this->storageMock->expects($this->once())
92
            ->method('set')
93
            ->with(
94
                $this->equalTo($key),
95
                $this->equalTo($value),
96
                $this->equalTo(60)
97
            );
98
99
        $this->cache->set($key, $value);
100
    }
101
102 View Code Duplication
    public function testGet()
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...
103
    {
104
        $key = 'key';
105
106
        $this->storageMock->expects($this->once())
107
            ->method('get')
108
            ->with(
109
                $this->equalTo($key)
110
            );
111
112
        $this->cache->get($key);
113
    }
114
115 View Code Duplication
    public function testDelete()
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...
116
    {
117
        $key = 'key';
118
119
        $this->storageMock->expects($this->once())
120
            ->method('delete')
121
            ->with(
122
                $this->equalTo($key)
123
            );
124
125
        $this->cache->delete($key);
126
    }
127
128
    public function testWithCacheStorage()
129
    {
130
        $newStorageMock = $this->getMockBuilder('\Ds\Cache\Interfaces\CacheStorageInterface')
131
            ->getMock();
132
133
        $newCache = $this->cache->withCacheStorage($newStorageMock);
134
        $this->assertEquals($newStorageMock, $newCache->getCacheStorage());
135
136
    }
137
138
    public function testGetCacheStorage()
139
    {
140
        $expected = $this->storageMock;
141
        $actual = $this->cache->getCacheStorage();
142
        $this->assertEquals($expected, $actual);
143
    }
144
}
145