Completed
Push — master ( 4e532e...59ecf7 )
by Dan
02:41
created

CacheTest::testHas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
rs 9.4285
cc 1
eloc 7
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);
20
    }
21
22 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...
23
    {
24
25
        $key = 'key';
26
27
        $this->storageMock->expects($this->once())
28
            ->method('has')
29
            ->with(
30
                $this->equalTo($key)
31
            );
32
33
        $this->cache->has($key);
34
    }
35
36 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...
37
    {
38
39
        $key = 'key';
40
        $value = 'value';
41
        $expires = 10;
42
43
        $this->storageMock->expects($this->once())
44
            ->method('set')
45
            ->with(
46
                $this->equalTo($key),
47
                $this->equalTo($value),
48
                $this->equalTo($expires)
49
            );
50
51
        $this->cache->set($key, $value, $expires);
52
    }
53
54 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...
55
    {
56
        $key = 'key';
57
58
        $this->storageMock->expects($this->once())
59
            ->method('get')
60
            ->with(
61
                $this->equalTo($key)
62
            );
63
64
        $this->cache->get($key);
65
    }
66
67 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...
68
    {
69
        $key = 'key';
70
71
        $this->storageMock->expects($this->once())
72
            ->method('delete')
73
            ->with(
74
                $this->equalTo($key)
75
            );
76
77
        $this->cache->delete($key);
78
    }
79
80
    public function testWithCacheStorage()
81
    {
82
        $newStorageMock = $this->getMockBuilder('\Ds\Cache\Interfaces\CacheStorageInterface')
83
            ->getMock();
84
85
        $newCache = $this->cache->withCacheStorage($newStorageMock);
86
        $this->assertEquals($newStorageMock, $newCache->getCacheStorage());
87
88
    }
89
90
    public function testGetCacheStorage()
91
    {
92
        $expected = $this->storageMock;
93
        $actual = $this->cache->getCacheStorage();
94
        $this->assertEquals($expected, $actual);
95
    }
96
}
97