forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheFileStoreTest.php
More file actions
executable file
·105 lines (84 loc) · 3.6 KB
/
CacheFileStoreTest.php
File metadata and controls
executable file
·105 lines (84 loc) · 3.6 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
100
101
102
103
104
105
<?php
use Illuminate\Cache\FileStore;
class CacheFileStoreTest extends PHPUnit_Framework_TestCase {
public function testNullIsReturnedIfFileDoesntExist()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('exists')->will($this->returnValue(false));
$store = new FileStore($files, __DIR__);
$value = $store->get('foo');
$this->assertNull($value);
}
public function testPutCreatesMissingDirectories()
{
$files = $this->mockFilesystem();
$md5 = md5('foo');
$full_dir = __DIR__.'/'.substr($md5, 0, 2).'/'.substr($md5, 2, 2);
$files->expects($this->once())->method('makeDirectory')->with($this->equalTo($full_dir), $this->equalTo(0777), $this->equalTo(true));
$files->expects($this->once())->method('put')->with($this->equalTo($full_dir.'/'.$md5));
$store = new FileStore($files, __DIR__);
$store->put('foo', '0000000000', 0);
}
public function testExpiredItemsReturnNull()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('exists')->will($this->returnValue(true));
$contents = '0000000000';
$files->expects($this->once())->method('get')->will($this->returnValue($contents));
$store = $this->getMock('Illuminate\Cache\FileStore', array('forget'), array($files, __DIR__));
$store->expects($this->once())->method('forget');
$value = $store->get('foo');
$this->assertNull($value);
}
public function testValidItemReturnsContents()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('exists')->will($this->returnValue(true));
$contents = '9999999999'.serialize('Hello World');
$files->expects($this->once())->method('get')->will($this->returnValue($contents));
$store = new FileStore($files, __DIR__);
$this->assertEquals('Hello World', $store->get('foo'));
}
public function testStoreItemProperlyStoresValues()
{
$files = $this->mockFilesystem();
$store = $this->getMock('Illuminate\Cache\FileStore', array('expiration'), array($files, __DIR__));
$store->expects($this->once())->method('expiration')->with($this->equalTo(10))->will($this->returnValue(1111111111));
$contents = '1111111111'.serialize('Hello World');
$md5 = md5('foo');
$cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5), $this->equalTo($contents));
$store->put('foo', 'Hello World', 10);
}
public function testForeversAreStoredWithHighTimestamp()
{
$files = $this->mockFilesystem();
$contents = '9999999999'.serialize('Hello World');
$md5 = md5('foo');
$cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5), $this->equalTo($contents));
$store = new FileStore($files, __DIR__);
$store->forever('foo', 'Hello World', 10);
}
public function testRemoveDeletesFile()
{
$files = $this->mockFilesystem();
$md5 = md5('foo');
$cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
$files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5));
$store = new FileStore($files, __DIR__);
$store->forget('foo');
}
public function testFlushCleansDirectory()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue(array('foo')));
$files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'));
$store = new FileStore($files, __DIR__);
$store->flush();
}
protected function mockFilesystem()
{
return $this->getMock('Illuminate\Filesystem\Filesystem');
}
}