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
·128 lines (113 loc) · 5.38 KB
/
CacheFileStoreTest.php
File metadata and controls
executable file
·128 lines (113 loc) · 5.38 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
use Illuminate\Cache\FileStore;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
class CacheFileStoreTest extends PHPUnit_Framework_TestCase
{
public function testNullIsReturnedIfFileDoesntExist()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('get')->will($this->throwException(new FileNotFoundException()));
$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();
$contents = '0000000000';
$files->expects($this->once())->method('get')->will($this->returnValue($contents));
$store = $this->getMock('Illuminate\Cache\FileStore', ['forget'], [$files, __DIR__]);
$store->expects($this->once())->method('forget');
$value = $store->get('foo');
$this->assertNull($value);
}
public function testValidItemReturnsContents()
{
$files = $this->mockFilesystem();
$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', ['expiration'], [$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 testForeversAreNotRemovedOnIncrement()
{
$files = $this->mockFilesystem();
$contents = '9999999999'.serialize('Hello World');
$store = new FileStore($files, __DIR__);
$store->forever('foo', 'Hello World');
$store->increment('foo');
$files->expects($this->once())->method('get')->will($this->returnValue($contents));
$this->assertEquals('Hello World', $store->get('foo'));
}
public function testRemoveDeletesFileDoesntExist()
{
$files = $this->mockFilesystem();
$md5 = md5('foobull');
$cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
$files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5))->will($this->returnValue(false));
$store = new FileStore($files, __DIR__);
$store->forget('foobull');
}
public function testRemoveDeletesFile()
{
$files = $this->mockFilesystem();
$md5 = md5('foobar');
$cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
$store = new FileStore($files, __DIR__);
$store->put('foobar', 'Hello Baby', 10);
$files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5))->will($this->returnValue(true));
$files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5));
$store->forget('foobar');
}
public function testFlushCleansDirectory()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->will($this->returnValue(true));
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue(['foo']));
$files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'));
$store = new FileStore($files, __DIR__);
$store->flush();
}
public function testFlushIgnoreNonExistingDirectory()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'--wrong'))->will($this->returnValue(false));
$store = new FileStore($files, __DIR__.'--wrong');
$store->flush();
}
protected function mockFilesystem()
{
return $this->getMock('Illuminate\Filesystem\Filesystem');
}
}