MemcacheStorageTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Tests\Cache;
4
5
use Ds\Cache\CacheStorageInterface;
6
use Ds\Cache\Storage\MemcacheStorage;
7
8
9
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
10
11
/**
12
 * Class MemcacheStorageTest
13
 * @package Tests\Cache
14
 */
15
class MemcacheStorageTest extends \PHPUnit\Framework\TestCase
16
{
17
    /**
18
     * @var \DateInterval
19
     */
20
    public $ttl;
21
22
    /**
23
     * @var \PHPUnit_Framework_MockObject_MockObject
24
     */
25
    public $memcacheMock;
26
27
    /**
28
     * @var \Memcached
29
     */
30
    public $memcacheStorage;
31
32
    /**
33
     * Set up.
34
     */
35
    public function setUp()
36
    {
37
        $this->ttl = new \DateInterval('P1M');
38
        $this->memcacheMock = $this->getMockBuilder('\Memcached')->getMock();
39
        $this->memcacheStorage = new MemcacheStorage($this->memcacheMock,'localhost',11211, $this->ttl);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Ds\Cache\Storage\Me...st', 11211, $this->ttl) of type object<Ds\Cache\Storage\MemcacheStorage> is incompatible with the declared type object<Memcached> of property $memcacheStorage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
    }
41
42
    public function testAddServer()
43
    {
44
45
        $server = 'localhost';
46
        $port = '11211';
47
48
        $this->memcacheMock->expects($this->once())
49
            ->method('addServer')
50
            ->with(
51
                $this->equalTo($server),
52
                $this->equalTo($port)
53
            );
54
55
        $this->memcacheStorage->addServer($server, $port);
56
    }
57
58 View Code Duplication
    public function testFlush()
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...
59
    {
60
        $delay = 10;
61
        $this->memcacheMock->expects($this->once())
62
            ->method('flush')
63
            ->with(
64
                $this->equalTo($delay)
65
            );
66
        $this->memcacheStorage->flush($delay);
67
    }
68
69
    /**
70
     * @dataProvider hasCacheProvider
71
     */
72
    public function testHas($expected)
73
    {
74
        $key = 'key';
75
        $this->memcacheMock->expects($this->once())
76
            ->method('get')
77
            ->with(
78
                $this->equalTo($key)
79
            )
80
            ->willReturn($expected);
81
        $this->assertEquals($expected, $this->memcacheStorage->has($key));
82
    }
83
    public function hasCacheProvider()
84
    {
85
        return array(
86
            [true],
87
            [false]
88
        );
89
    }
90
    public function testSet()
91
    {
92
        $key = 'key';
93
        $value = 'value';
94
        $expires = 10;
95
        $this->memcacheMock->expects($this->once())
96
            ->method('set')
97
            ->with(
98
                $this->equalTo($key),
99
                $this->equalTo($value),
100
                $this->equalTo($expires)
101
            );
102
        $this->memcacheStorage->set($key, $value, $expires);
103
    }
104 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...
105
    {
106
        $key = 'key';
107
        $this->memcacheMock->expects($this->once())
108
            ->method('get')
109
            ->with(
110
                $this->equalTo($key)
111
            );
112
        $this->memcacheStorage->get($key);
113
    }
114 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...
115
    {
116
        $key = 'key';
117
        $this->memcacheMock->expects($this->once())
118
            ->method('delete')
119
            ->with(
120
                $this->equalTo($key)
121
            );
122
        $this->memcacheStorage->delete($key);
123
    }
124
125
126
}
127