forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheRepositoryTest.php
More file actions
executable file
·92 lines (70 loc) · 2.52 KB
/
CacheRepositoryTest.php
File metadata and controls
executable file
·92 lines (70 loc) · 2.52 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 CacheRepositoryTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testGetReturnsValueFromCache()
{
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->once()->with('foo')->andReturn('bar');
$this->assertEquals('bar', $repo->get('foo'));
}
public function testDefaultValueIsReturned()
{
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->andReturn(null);
$this->assertEquals('bar', $repo->get('foo', 'bar'));
$this->assertEquals('baz', $repo->get('boom', function() { return 'baz'; }));
}
public function testSettingDefaultCacheTime()
{
$repo = $this->getRepository();
$repo->setDefaultCacheTime(10);
$this->assertEquals(10, $repo->getDefaultCacheTime());
}
public function testHasMethod()
{
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->once()->with('foo')->andReturn(null);
$repo->getStore()->shouldReceive('get')->once()->with('bar')->andReturn('bar');
$this->assertTrue($repo->has('bar'));
$this->assertFalse($repo->has('foo'));
}
public function testRememberMethodCallsPutAndReturnsDefault()
{
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->andReturn(null);
$repo->getStore()->shouldReceive('put')->once()->with('foo', 'bar', 10);
$result = $repo->remember('foo', 10, function() { return 'bar'; });
$this->assertEquals('bar', $result);
/**
* Use Carbon object...
*/
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->andReturn(null);
$repo->getStore()->shouldReceive('put')->once()->with('foo', 'bar', 10);
$result = $repo->remember('foo', Carbon\Carbon::now()->addMinutes(10), function() { return 'bar'; });
$this->assertEquals('bar', $result);
}
public function testRememberForeverMethodCallsForeverAndReturnsDefault()
{
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->andReturn(null);
$repo->getStore()->shouldReceive('forever')->once()->with('foo', 'bar');
$result = $repo->rememberForever('foo', function() { return 'bar'; });
$this->assertEquals('bar', $result);
}
public function testRegisterMacroWithNonStaticCall()
{
$repo = $this->getRepository();
$repo::macro(__CLASS__, function() { return 'Taylor'; });
$this->assertEquals($repo->{__CLASS__}(), 'Taylor');
}
protected function getRepository()
{
return new Illuminate\Cache\Repository(m::mock('Illuminate\Cache\StoreInterface'));
}
}