forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheRedisStoreTest.php
More file actions
executable file
·99 lines (75 loc) · 3.09 KB
/
CacheRedisStoreTest.php
File metadata and controls
executable file
·99 lines (75 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
use Mockery as m;
class CacheRedisStoreTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testGetReturnsNullWhenNotFound()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('get')->once()->with('prefix:foo')->andReturn(null);
$this->assertNull($redis->get('foo'));
}
public function testRedisValueIsReturned()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('get')->once()->with('prefix:foo')->andReturn(serialize('foo'));
$this->assertEquals('foo', $redis->get('foo'));
}
public function testRedisValueIsReturnedForNumerics()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('get')->once()->with('prefix:foo')->andReturn(1);
$this->assertEquals(1, $redis->get('foo'));
}
public function testSetMethodProperlyCallsRedis()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('setex')->once()->with('prefix:foo', 60 * 60, serialize('foo'));
$redis->put('foo', 'foo', 60);
}
public function testSetMethodProperlyCallsRedisForNumerics()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('setex')->once()->with('prefix:foo', 60 * 60, 1);
$redis->put('foo', 1, 60);
}
public function testIncrementMethodProperlyCallsRedis()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('incrby')->once()->with('prefix:foo', 5);
$redis->increment('foo', 5);
}
public function testDecrementMethodProperlyCallsRedis()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('decrby')->once()->with('prefix:foo', 5);
$redis->decrement('foo', 5);
}
public function testStoreItemForeverProperlyCallsRedis()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('set')->once()->with('prefix:foo', serialize('foo'));
$redis->forever('foo', 'foo', 60);
}
public function testForgetMethodProperlyCallsRedis()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('del')->once()->with('prefix:foo');
$redis->forget('foo');
}
protected function getRedis()
{
return new Illuminate\Cache\RedisStore(m::mock('Illuminate\Redis\Database'), 'prefix');
}
}