Test Failed
Pull Request — master (#2)
by Joao
02:20
created

CachePSR16Test::testTtl()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
rs 8.8571
cc 3
eloc 21
nc 3
nop 1
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 9 and the first side effect is on line 7.

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 Test;
4
5
use ByJG\Cache\Psr16\NoCacheEngine;
6
7
require_once 'BaseCacheTest.php';
8
9
class CachePSR16Test extends BaseCacheTest
10
{
11
    /**
12
     * @dataProvider CachePoolProvider
13
     * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
14
     */
15
    public function testGetOneItem(\ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine)
16
    {
17
        $this->cacheEngine = $cacheEngine;
18
19
        if ($cacheEngine->isAvailable()) {
20
            // First time
21
            $item = $cacheEngine->get('chave', null);
22
            $this->assertEquals(null, $item);
23
            $item = $cacheEngine->get('chave', 'default');
24
            $this->assertEquals('default', $item);
25
26
            // Set object
27
            $cacheEngine->set('chave', 'valor');
28
29
            // Get Object
30
            if (!($cacheEngine instanceof \ByJG\Cache\Psr16\NoCacheEngine)) {
31
                $item2 = $cacheEngine->get('chave', 'default');
32
                $this->assertEquals('valor', $item2);
33
            }
34
35
            // Remove
36
            $cacheEngine->delete('chave');
37
38
            // Check Removed
39
            $item = $cacheEngine->get('chave');
40
            $this->assertEquals(null, $item);
41
        } else {
42
            $this->markTestIncomplete('Object is not fully functional');
43
        }
44
    }
45
46
    /**
47
     * @dataProvider CachePoolProvider
48
     * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
49
     */
50
    public function testGetMultipleItems(\ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine)
51
    {
52
        $this->cacheEngine = $cacheEngine;
53
54
        if ($cacheEngine->isAvailable()) {
55
            // First time
56
            $items = $cacheEngine->getMultiple(['chave1', 'chave2']);
0 ignored issues
show
Documentation introduced by
array('chave1', 'chave2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
            $this->assertEquals(null, $items['chave1']);
58
            $this->assertEquals(null, $items['chave2']);
59
            $items = $cacheEngine->getMultiple(['chave1', 'chave2'], 'default');
0 ignored issues
show
Documentation introduced by
array('chave1', 'chave2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
            $this->assertEquals('default', $items['chave1']);
61
            $this->assertEquals('default', $items['chave2']);
62
63
            // Set object
64
            $cacheEngine->set('chave1', 'valor1');
65
            $cacheEngine->set('chave2', 'valor2');
66
67
            // Get Object
68
            if (!($cacheEngine instanceof \ByJG\Cache\Psr16\NoCacheEngine)) {
69
                $item2 = $cacheEngine->getMultiple(['chave1', 'chave2']);
0 ignored issues
show
Documentation introduced by
array('chave1', 'chave2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
                $this->assertEquals('valor1', $item2['chave1']);
71
                $this->assertEquals('valor2', $item2['chave2']);
72
            }
73
74
            // Remove
75
            $cacheEngine->deleteMultiple(['chave1', 'chave2']);
0 ignored issues
show
Documentation introduced by
array('chave1', 'chave2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
76
77
            // Check Removed
78
            $items = $cacheEngine->getMultiple(['chave1', 'chave2']);
0 ignored issues
show
Documentation introduced by
array('chave1', 'chave2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
            $this->assertEquals(null, $items['chave1']);
80
            $this->assertEquals(null, $items['chave2']);
81
        } else {
82
            $this->markTestIncomplete('Object is not fully functional');
83
        }
84
    }
85
86
    /**
87
     * @dataProvider CachePoolProvider
88
     * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
89
     */
90
    public function testTtl(\ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine)
91
    {
92
        $this->cacheEngine = $cacheEngine;
93
94
        if ($cacheEngine->isAvailable()) {
95
            // First time
96
            $item = $cacheEngine->get('chave');
97
            $this->assertEquals(null, $item);
98
            $this->assertFalse($cacheEngine->has('chave'));
99
            $item2 = $cacheEngine->get('chave2');
100
            $this->assertEquals(null, $item2);
101
            $this->assertFalse($cacheEngine->has('chave2'));
102
103
            // Set object
104
            $cacheEngine->set('chave', 'valor', 2);
105
            $cacheEngine->set('chave2', 'valor2', 2);
106
107
            // Get Object
108
            if (!($cacheEngine instanceof \ByJG\Cache\Psr16\NoCacheEngine)) {
109
                $item2 = $cacheEngine->get('chave');
110
                $this->assertEquals('valor', $item2);
111
                $this->assertTrue($cacheEngine->has('chave2'));
112
                sleep(3);
113
                $item2 = $cacheEngine->get('chave');
114
                $this->assertEquals(null, $item2);
115
                $this->assertFalse($cacheEngine->has('chave2'));
116
            }
117
        } else {
118
            $this->markTestIncomplete('Object is not fully functional');
119
        }
120
    }
121
122
    /**
123
     * @dataProvider CachePoolProvider
124
     * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
125
     */
126
    public function testCacheObject(\ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine)
127
    {
128
        $this->cacheEngine = $cacheEngine;
129
130
        if ($cacheEngine->isAvailable()) {
131
            // First time
132
            $item = $cacheEngine->get('chave');
133
            $this->assertEquals(null, $item);
134
135
            // Set object
136
            $model = new Model(10, 20);
137
            $cacheEngine->set('chave', $model);
138
139
            // Get Object
140
            if (!($cacheEngine instanceof \ByJG\Cache\Psr16\NoCacheEngine)) {
141
                $item2 = $cacheEngine->get('chave');
142
                $this->assertEquals($model, $item2);
143
            }
144
145
            // Delete
146
            $cacheEngine->delete('chave');
147
            $item = $cacheEngine->get('chave');
148
            $this->assertEquals(null, $item);
149
        } else {
150
            $this->markTestIncomplete('Object is not fully functional');
151
        }
152
    }
153
154
    /**
155
     * @dataProvider CachePoolProvider
156
     * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
157
     */
158
    public function testClear(\ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine)
159
    {
160
        $this->cacheEngine = $cacheEngine;
161
162
        if ($cacheEngine->isAvailable()) {
163
            // Values
164
            $empty = [
165
                'chave'  => null,
166
                'chave2' => null,
167
                'chave3' => null
168
            ];
169
            $set = [
170
                'chave'  => 'val',
171
                'chave2' => 'val2',
172
                'chave3' => 'val3'
173
            ];
174
175
            // First time
176
            $item = $cacheEngine->getMultiple(['chave', 'chave2', 'chave3']);
0 ignored issues
show
Documentation introduced by
array('chave', 'chave2', 'chave3') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
            $this->assertEquals($empty, $item);
178
179
            // Set and Check
180
            $cacheEngine->setMultiple($set);
0 ignored issues
show
Documentation introduced by
$set is of type array<string,string,{"ch...ng","chave3":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
181
            if (!($cacheEngine instanceof NoCacheEngine)) {
182
                $item = $cacheEngine->getMultiple(['chave', 'chave2', 'chave3']);
0 ignored issues
show
Documentation introduced by
array('chave', 'chave2', 'chave3') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
183
                $this->assertEquals($set, $item);
184
            }
185
186
            // Clear and Check
187
            $cacheEngine->clear();
188
            $item = $cacheEngine->getMultiple(['chave', 'chave2', 'chave3']);
0 ignored issues
show
Documentation introduced by
array('chave', 'chave2', 'chave3') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a object<Psr\SimpleCache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
189
            $this->assertEquals($empty, $item);
190
        } else {
191
            $this->markTestIncomplete('Object is not fully functional');
192
        }
193
    }
194
}
195