1
|
|
|
<?php |
2
|
|
|
namespace tests; |
3
|
|
|
|
4
|
|
|
use Soupmix; |
5
|
|
|
|
6
|
|
|
class RedisCacheTest extends \PHPUnit_Framework_TestCase |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var \Soupmix\Cache\RedisCache $client |
10
|
|
|
*/ |
11
|
|
|
protected $client = null; |
12
|
|
|
|
13
|
|
|
protected function setUp() |
14
|
|
|
{ |
15
|
|
|
$this->client = new Soupmix\Cache\RedisCache([ |
16
|
|
|
|
17
|
|
|
'host' => '127.0.0.1', |
18
|
|
|
]); |
19
|
|
|
$this->client->clear(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testSetGetDeleteItem() |
23
|
|
|
{ |
24
|
|
|
$ins1 = $this->client->set('test1','value1'); |
25
|
|
|
$this->assertTrue($ins1); |
26
|
|
|
$value1 = $this->client->get('test1'); |
27
|
|
|
$this->assertEquals('value1',$value1); |
28
|
|
|
$delete = $this->client->delete('test1'); |
29
|
|
|
$this->assertTrue($delete); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testMultiSetGetDeleteItems() |
33
|
|
|
{ |
34
|
|
|
$cacheData = [ |
35
|
|
|
'test1' => 'value1', |
36
|
|
|
'test2' => 'value2', |
37
|
|
|
'test3' => 'value3', |
38
|
|
|
'test4' => 'value4' |
39
|
|
|
]; |
40
|
|
|
$insMulti = $this->client->setMultiple($cacheData); |
41
|
|
|
$this->assertTrue($insMulti); |
42
|
|
|
|
43
|
|
|
$getMulti = $this->client->getMultiple(array_keys($cacheData)); |
44
|
|
|
|
45
|
|
|
foreach ($cacheData as $key => $value) { |
46
|
|
|
$this->assertArrayHasKey($key, $getMulti); |
47
|
|
|
$this->assertEquals($value, $getMulti[$key]); |
48
|
|
|
} |
49
|
|
|
$deleteMulti = $this->client->deleteMultiple(array_keys($cacheData)); |
50
|
|
|
|
51
|
|
|
foreach ($cacheData as $key => $value) { |
52
|
|
|
$this->assertTrue($deleteMulti[$key]); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testIncrementDecrementItem() |
57
|
|
|
{ |
58
|
|
|
$counter_i_1 = $this->client->increment('counter', 1); |
59
|
|
|
$this->assertEquals(1, $counter_i_1); |
60
|
|
|
$counter_i_3 = $this->client->increment('counter', 2); |
61
|
|
|
$this->assertEquals(3, $counter_i_3); |
62
|
|
|
$counter_i_4 = $this->client->increment('counter'); |
63
|
|
|
$this->assertEquals(4, $counter_i_4); |
64
|
|
|
$counter_d_3 = $this->client->decrement('counter'); |
65
|
|
|
$this->assertEquals(3, $counter_d_3); |
66
|
|
|
$counter_d_1 = $this->client->decrement('counter', 2); |
67
|
|
|
$this->assertEquals(1, $counter_d_1); |
68
|
|
|
$counter_d_0 = $this->client->decrement('counter', 1); |
69
|
|
|
$this->assertEquals(0, $counter_d_0); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testClear(){ |
73
|
|
|
$clear = $this->client->clear(); |
74
|
|
|
$this->assertTrue($clear); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|