forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheTaggedCacheTest.php
More file actions
92 lines (81 loc) · 3.63 KB
/
CacheTaggedCacheTest.php
File metadata and controls
92 lines (81 loc) · 3.63 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
<?php
use Mockery as m;
use Illuminate\Cache\ArrayStore;
class CacheTaggedCacheTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testCacheCanBeSavedWithMultipleTags()
{
$store = new ArrayStore;
$tags = ['bop', 'zap'];
$store->tags($tags)->put('foo', 'bar', 10);
$this->assertEquals('bar', $store->tags($tags)->get('foo'));
}
public function testCacheCanBeSetWithDatetimeArgument()
{
$store = new ArrayStore;
$tags = ['bop', 'zap'];
$duration = new DateTime();
$duration->add(new DateInterval('PT10M'));
$store->tags($tags)->put('foo', 'bar', $duration);
$this->assertEquals('bar', $store->tags($tags)->get('foo'));
}
public function testCacheSavedWithMultipleTagsCanBeFlushed()
{
$store = new ArrayStore;
$tags1 = ['bop', 'zap'];
$store->tags($tags1)->put('foo', 'bar', 10);
$tags2 = ['bam', 'pow'];
$store->tags($tags2)->put('foo', 'bar', 10);
$store->tags('zap')->flush();
$this->assertNull($store->tags($tags1)->get('foo'));
$this->assertEquals('bar', $store->tags($tags2)->get('foo'));
}
public function testTagsWithStringArgument()
{
$store = new ArrayStore;
$store->tags('bop')->put('foo', 'bar', 10);
$this->assertEquals('bar', $store->tags('bop')->get('foo'));
}
public function testTagsCacheForever()
{
$store = new ArrayStore;
$tags = ['bop', 'zap'];
$store->tags($tags)->forever('foo', 'bar');
$this->assertEquals('bar', $store->tags($tags)->get('foo'));
}
public function testRedisCacheTagsPushForeverKeysCorrectly()
{
$store = m::mock('Illuminate\Contracts\Cache\Store');
$tagSet = m::mock('Illuminate\Cache\TagSet', [$store, ['foo', 'bar']]);
$tagSet->shouldReceive('getNamespace')->andReturn('foo|bar');
$tagSet->shouldReceive('getNames')->andReturn(['foo', 'bar']);
$redis = new Illuminate\Cache\RedisTaggedCache($store, $tagSet);
$store->shouldReceive('getPrefix')->andReturn('prefix:');
$store->shouldReceive('connection')->andReturn($conn = m::mock('StdClass'));
$conn->shouldReceive('lpush')->once()->with('prefix:foo:forever', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('lpush')->once()->with('prefix:bar:forever', 'prefix:'.sha1('foo|bar').':key1');
$store->shouldReceive('forever')->with(sha1('foo|bar').':key1', 'key1:value');
$redis->forever('key1', 'key1:value');
}
public function testRedisCacheForeverTagsCanBeFlushed()
{
$store = m::mock('Illuminate\Contracts\Cache\Store');
$tagSet = m::mock('Illuminate\Cache\TagSet', [$store, ['foo', 'bar']]);
$tagSet->shouldReceive('getNamespace')->andReturn('foo|bar');
$redis = new Illuminate\Cache\RedisTaggedCache($store, $tagSet);
$store->shouldReceive('getPrefix')->andReturn('prefix:');
$store->shouldReceive('connection')->andReturn($conn = m::mock('StdClass'));
$conn->shouldReceive('lrange')->once()->with('prefix:foo:forever', 0, -1)->andReturn(['key1', 'key2']);
$conn->shouldReceive('lrange')->once()->with('prefix:bar:forever', 0, -1)->andReturn(['key3']);
$conn->shouldReceive('del')->once()->with('key1', 'key2');
$conn->shouldReceive('del')->once()->with('key3');
$conn->shouldReceive('del')->once()->with('prefix:foo:forever');
$conn->shouldReceive('del')->once()->with('prefix:bar:forever');
$tagSet->shouldReceive('reset')->once();
$redis->flush();
}
}