Completed
Push — master ( b81087...23b3e4 )
by Dan
05:58
created

CacheTest::testSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 1
eloc 11
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
    public function testSet()
23
    {
24
25
        $key = 'key';
26
        $value = 'value';
27
        $expires = 10;
28
29
        $this->storageMock->expects($this->once())
30
            ->method('set')
31
            ->with(
32
                $this->equalTo($key),
33
                $this->equalTo($value),
34
                $this->equalTo($expires)
35
            );
36
37
        $this->cache->set($key, $value, $expires);
38
    }
39
40 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...
41
    {
42
        $key = 'key';
43
44
        $this->storageMock->expects($this->once())
45
            ->method('get')
46
            ->with(
47
                $this->equalTo($key)
48
            );
49
50
        $this->cache->get($key);
51
    }
52
53 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...
54
    {
55
        $key = 'key';
56
57
        $this->storageMock->expects($this->once())
58
            ->method('delete')
59
            ->with(
60
                $this->equalTo($key)
61
            );
62
63
        $this->cache->delete($key);
64
    }
65
66
    public function testWithCacheStorage()
67
    {
68
        $newStorageMock = $this->getMockBuilder('\Ds\Cache\Interfaces\CacheStorageInterface')
69
            ->getMock();
70
71
        $newCache = $this->cache->withCacheStorage($newStorageMock);
72
        $this->assertEquals($newStorageMock, $newCache->getCacheStorage());
73
74
    }
75
76
    public function testGetCacheStorage()
77
    {
78
        $expected = $this->storageMock;
79
        $actual = $this->cache->getCacheStorage();
80
        $this->assertEquals($expected, $actual);
81
    }
82
}
83