|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BenTools\Currency\Tests\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use BenTools\Currency\Cache\ArrayCache; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class ArrayCacheTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
public function testGet() |
|
12
|
|
|
{ |
|
13
|
|
|
$cache = new ArrayCache(); |
|
14
|
|
|
$cache->set('foo', 'bar'); |
|
15
|
|
|
$this->assertEquals('bar', $cache->get('foo')); |
|
16
|
|
|
$this->assertEquals(null, $cache->get('baz')); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testDelete() |
|
20
|
|
|
{ |
|
21
|
|
|
$cache = new ArrayCache(); |
|
22
|
|
|
$cache->set('foo', 'bar'); |
|
23
|
|
|
$cache->delete('foo'); |
|
24
|
|
|
$this->assertEquals(null, $cache->get('foo')); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testClear() |
|
28
|
|
|
{ |
|
29
|
|
|
$cache = new ArrayCache(); |
|
30
|
|
|
$cache->set('foo', 'bar'); |
|
31
|
|
|
$cache->clear(); |
|
32
|
|
|
$this->assertEquals(null, $cache->get('foo')); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testGetMultiple() |
|
36
|
|
|
{ |
|
37
|
|
|
$cache = new ArrayCache(); |
|
38
|
|
|
$values = [ |
|
39
|
|
|
'foo' => 'bar', |
|
40
|
|
|
'baz' => 'bat' |
|
41
|
|
|
]; |
|
42
|
|
|
$cache->setMultiple($values); |
|
|
|
|
|
|
43
|
|
|
$this->assertEquals($values, iterable_to_array($cache->getMultiple(array_keys($values)))); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testDeleteMultiple() |
|
47
|
|
|
{ |
|
48
|
|
|
$cache = new ArrayCache(); |
|
49
|
|
|
$values = [ |
|
50
|
|
|
'foo' => 'bar', |
|
51
|
|
|
'baz' => 'bat', |
|
52
|
|
|
'bar' => 'foo', |
|
53
|
|
|
]; |
|
54
|
|
|
$cache->setMultiple($values); |
|
|
|
|
|
|
55
|
|
|
$cache->deleteMultiple(['foo', 'bar']); |
|
|
|
|
|
|
56
|
|
|
$this->assertEquals([ |
|
57
|
|
|
'foo' => null, |
|
58
|
|
|
'baz' => 'bat', |
|
59
|
|
|
'bar' => null, |
|
60
|
|
|
], iterable_to_array($cache->getMultiple(array_keys($values)))); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testHas() |
|
64
|
|
|
{ |
|
65
|
|
|
$cache = new ArrayCache(); |
|
66
|
|
|
$cache->set('foo', 'bar'); |
|
67
|
|
|
$this->assertTrue($cache->has('foo')); |
|
68
|
|
|
$this->assertFalse($cache->has('baz')); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testDefaultTtl() |
|
72
|
|
|
{ |
|
73
|
|
|
$cache = new ArrayCache(1); |
|
74
|
|
|
$cache->set('foo', 'bar'); |
|
75
|
|
|
$this->assertTrue($cache->has('foo')); |
|
76
|
|
|
$this->assertEquals('bar', $cache->get('foo')); |
|
77
|
|
|
sleep(1); |
|
78
|
|
|
$this->assertFalse($cache->has('foo')); |
|
79
|
|
|
$this->assertNull($cache->get('foo')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testTtlOverride() |
|
83
|
|
|
{ |
|
84
|
|
|
$cache = new ArrayCache(1); |
|
85
|
|
|
$cache->set('foo', 'bar', 2); |
|
86
|
|
|
$this->assertTrue($cache->has('foo')); |
|
87
|
|
|
$this->assertEquals('bar', $cache->get('foo')); |
|
88
|
|
|
sleep(1); |
|
89
|
|
|
$this->assertTrue($cache->has('foo')); |
|
90
|
|
|
$this->assertEquals('bar', $cache->get('foo')); |
|
91
|
|
|
sleep(1); |
|
92
|
|
|
$this->assertFalse($cache->has('foo')); |
|
93
|
|
|
$this->assertNull($cache->get('foo')); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
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: