-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheableTest.php
More file actions
160 lines (122 loc) · 3.85 KB
/
Copy pathCacheableTest.php
File metadata and controls
160 lines (122 loc) · 3.85 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
use Illuminate\Database\Eloquent\Model as EloquentModel;
use SimpleSoftwareIO\Cache\Cacheable;
use SimpleSoftwareIO\Cache\QueryCache;
class Model extends EloquentModel
{
use Cacheable;
}
class BustingModel extends EloquentModel
{
use Cacheable;
protected $cacheBusting = true;
}
class CacheableTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
Mockery::close();
}
/** @test */
public function the_correct_cache_store_is_returned_when_a_cache_store_is_set()
{
$model = new class() extends EloquentModel {
use Cacheable;
protected $cacheStore = 'fooStore';
};
$this->assertEquals('fooStore', $model->getCacheStore());
}
/** @test */
public function null_is_returned_when_a_cache_store_is_not_set()
{
$model = new Model();
$this->assertNull($model->getCacheStore());
}
/** @test */
public function cache_busting_returns_true_when_cache_busting_is_set()
{
$model = new class() extends EloquentModel {
use Cacheable;
protected $cacheBusting = true;
};
$this->assertTrue($model->getCacheBusting());
}
/** @test */
public function cache_busting_returns_false_when_no_cache_busting_is_set()
{
$model = new Model();
$this->assertFalse($model->getCacheBusting());
}
/** @test */
public function thirty_minutes_are_returned_when_no_cache_length_is_set()
{
$model = new Model();
$this->assertEquals(30, $model->getCacheLength());
}
/** @test */
public function the_correct_length_is_returned_when_a_length_is_set()
{
$model = new class() extends EloquentModel {
use Cacheable;
protected $cacheLength = 45;
};
$this->assertEquals(45, $model->getCacheLength());
}
/** @test */
public function insert_and_update_bust_the_cache_when_busting_is_enabled()
{
$model = Mockery::mock('BustingModel[queryCache]')
->shouldAllowMockingProtectedMethods();
$queryCache = Mockery::mock(QueryCache::class);
$queryCache->shouldReceive('flush')
->once();
$model->shouldReceive('queryCache')
->once()
->andReturn($queryCache);
$model->finishSave([]);
}
/** @test */
public function insert_and_update_do_not_bust_the_cache_when_busting_is_disabled()
{
$model = Mockery::mock('Model[queryCache]')
->shouldAllowMockingProtectedMethods();
$model->shouldReceive('queryCache')
->times(0);
$model->finishSave([]);
}
/** @test */
public function delete_should_bust_the_cache_when_busting_is_enabled()
{
$model = Mockery::mock('BustingModel[queryCache]')
->shouldAllowMockingProtectedMethods();
$queryCache = Mockery::mock(QueryCache::class);
$queryCache->shouldReceive('flush')
->once();
$model->shouldReceive('queryCache')
->once()
->andReturn($queryCache);
$model->delete();
}
/** @test */
public function delete_should_not_bust_the_cache_when_busting_is_disabled()
{
$model = Mockery::mock('Model[queryCache]')
->shouldAllowMockingProtectedMethods();
$model->shouldReceive('queryCache')
->times(0);
$model->delete();
}
/** @test */
public function flush_empties_the_cache()
{
$model = Mockery::mock('BustingModel[queryCache]')
->shouldAllowMockingProtectedMethods();
$queryCache = Mockery::mock(QueryCache::class);
$queryCache->shouldReceive('flush')
->once();
$model->shouldReceive('queryCache')
->once()
->andReturn($queryCache);
$model->flush();
}
}