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

CacheTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 60 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 3
dl 54
loc 90
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testHas() 13 13 1
A testSet() 17 17 1
A testGet() 12 12 1
A testDelete() 12 12 1
A testWithCacheStorage() 0 9 1
A testGetCacheStorage() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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