-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathCacheApcStoreTest.php
executable file
·135 lines (118 loc) · 4.61 KB
/
CacheApcStoreTest.php
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
129
130
131
132
133
134
135
<?php
namespace Illuminate\Tests\Cache;
use Illuminate\Cache\ApcStore;
use Illuminate\Cache\ApcWrapper;
use Mockery;
use PHPUnit\Framework\TestCase;
class CacheApcStoreTest extends TestCase
{
public function testGetReturnsNullWhenNotFound()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock();
$apc->expects($this->once())->method('get')->with($this->equalTo('foobar'))->willReturn(null);
$store = new ApcStore($apc, 'foo');
$this->assertNull($store->get('bar'));
}
public function testAPCValueIsReturned()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock();
$apc->expects($this->once())->method('get')->willReturn('bar');
$store = new ApcStore($apc);
$this->assertSame('bar', $store->get('foo'));
}
public function testAPCFalseValueIsReturned()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock();
$apc->expects($this->once())->method('get')->willReturn(false);
$store = new ApcStore($apc);
$this->assertFalse($store->get('foo'));
}
public function testGetMultipleReturnsNullWhenNotFoundAndValueWhenFound()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock();
$apc->expects($this->exactly(3))->method('get')->willReturnMap([
['foo', 'qux'],
['bar', null],
['baz', 'norf'],
]);
$store = new ApcStore($apc);
$this->assertEquals([
'foo' => 'qux',
'bar' => null,
'baz' => 'norf',
], $store->many(['foo', 'bar', 'baz']));
}
public function testSetMethodProperlyCallsAPC()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock();
$apc->expects($this->once())
->method('put')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(60))
->willReturn(true);
$store = new ApcStore($apc);
$result = $store->put('foo', 'bar', 60);
$this->assertTrue($result);
}
public function testSetMultipleMethodProperlyCallsAPC()
{
$apc = Mockery::mock(ApcWrapper::class);
$apc->shouldReceive('put')
->once()
->with('foo', 'bar', 60)
->andReturn(true);
$apc->shouldReceive('put')
->once()
->with('baz', 'qux', 60)
->andReturn(true);
$apc->shouldReceive('put')
->once()
->with('bar', 'norf', 60)
->andReturn(true);
$store = new ApcStore($apc);
$result = $store->putMany([
'foo' => 'bar',
'baz' => 'qux',
'bar' => 'norf',
], 60);
$this->assertTrue($result);
}
public function testIncrementMethodProperlyCallsAPC()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['increment'])->getMock();
$apc->expects($this->once())->method('increment')->with($this->equalTo('foo'), $this->equalTo(5));
$store = new ApcStore($apc);
$store->increment('foo', 5);
}
public function testDecrementMethodProperlyCallsAPC()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['decrement'])->getMock();
$apc->expects($this->once())->method('decrement')->with($this->equalTo('foo'), $this->equalTo(5));
$store = new ApcStore($apc);
$store->decrement('foo', 5);
}
public function testStoreItemForeverProperlyCallsAPC()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock();
$apc->expects($this->once())
->method('put')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(0))
->willReturn(true);
$store = new ApcStore($apc);
$result = $store->forever('foo', 'bar');
$this->assertTrue($result);
}
public function testForgetMethodProperlyCallsAPC()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['delete'])->getMock();
$apc->expects($this->once())->method('delete')->with($this->equalTo('foo'))->willReturn(true);
$store = new ApcStore($apc);
$result = $store->forget('foo');
$this->assertTrue($result);
}
public function testFlushesCached()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['flush'])->getMock();
$apc->expects($this->once())->method('flush')->willReturn(true);
$store = new ApcStore($apc);
$result = $store->flush();
$this->assertTrue($result);
}
}