1
1
<?php
2
2
/**
3
- * XcacheEngineTest file
4
- *
5
- * PHP 5
6
- *
7
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
3
+ * CakePHP(tm) <http://book.cakephp.org/2.0/en/development/testing.html>
8
4
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
9
5
*
10
6
* Licensed under The MIT License
11
7
* Redistributions of files must retain the above copyright notice
12
8
*
13
9
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
14
10
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
15
- * @package Cake.Test.Case.Cache.Engine
16
11
* @since CakePHP(tm) v 1.2.0.5434
17
12
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
18
13
*/
19
14
namespace Cake \Test \TestCase \Cache \Engine ;
15
+
20
16
use Cake \Cache \Cache ;
21
17
use Cake \Core \Configure ;
22
18
use Cake \TestSuite \TestCase ;
@@ -38,9 +34,8 @@ public function setUp() {
38
34
if (!function_exists ('xcache_set ' )) {
39
35
$ this ->markTestSkipped ('Xcache is not installed or configured properly ' );
40
36
}
41
- $ this ->_cacheDisable = Configure::read ('Cache.disable ' );
42
37
Configure::write ('Cache.disable ' , false );
43
- Cache:: config ( ' xcache ' , array ( 'engine ' => 'Xcache ' , 'prefix ' => 'cake_ ' ) );
38
+ Configure:: write ( ' Cache. xcache ' , [ 'engine ' => 'Xcache ' , 'prefix ' => 'cake_ ' ] );
44
39
}
45
40
46
41
/**
@@ -50,10 +45,8 @@ public function setUp() {
50
45
*/
51
46
public function tearDown () {
52
47
parent ::tearDown ();
53
- Configure::write ('Cache.disable ' , $ this ->_cacheDisable );
54
48
Cache::drop ('xcache ' );
55
49
Cache::drop ('xcache_groups ' );
56
- Cache::config ('default ' );
57
50
}
58
51
59
52
/**
@@ -63,12 +56,12 @@ public function tearDown() {
63
56
*/
64
57
public function testSettings () {
65
58
$ settings = Cache::settings ();
66
- $ expecting = array (
59
+ $ expecting = [
67
60
'prefix ' => 'cake_ ' ,
68
61
'duration ' => 3600 ,
69
62
'probability ' => 100 ,
70
63
'engine ' => 'Xcache ' ,
71
- ) ;
64
+ ] ;
72
65
$ this ->assertTrue (isset ($ settings ['PHP_AUTH_USER ' ]));
73
66
$ this ->assertTrue (isset ($ settings ['PHP_AUTH_PW ' ]));
74
67
@@ -82,21 +75,21 @@ public function testSettings() {
82
75
* @return void
83
76
*/
84
77
public function testReadAndWriteCache () {
85
- Cache::set (array ( 'duration ' => 1 ) );
78
+ Cache::set ([ 'duration ' => 1 ], ' xcache ' );
86
79
87
- $ result = Cache::read ('test ' );
80
+ $ result = Cache::read ('test ' , ' xcache ' );
88
81
$ expecting = '' ;
89
82
$ this ->assertEquals ($ expecting , $ result );
90
83
91
84
$ data = 'this is a test of the emergency broadcasting system ' ;
92
- $ result = Cache::write ('test ' , $ data );
85
+ $ result = Cache::write ('test ' , $ data, ' xcache ' );
93
86
$ this ->assertTrue ($ result );
94
87
95
- $ result = Cache::read ('test ' );
88
+ $ result = Cache::read ('test ' , ' xcache ' );
96
89
$ expecting = $ data ;
97
90
$ this ->assertEquals ($ expecting , $ result );
98
91
99
- Cache::delete ('test ' );
92
+ Cache::delete ('test ' , ' xcache ' );
100
93
}
101
94
102
95
/**
@@ -105,26 +98,26 @@ public function testReadAndWriteCache() {
105
98
* @return void
106
99
*/
107
100
public function testExpiry () {
108
- Cache::set (array ( 'duration ' => 1 ) );
109
- $ result = Cache::read ('test ' );
101
+ Cache::set ([ 'duration ' => 1 ], ' xcache ' );
102
+ $ result = Cache::read ('test ' , ' xcache ' );
110
103
$ this ->assertFalse ($ result );
111
104
112
105
$ data = 'this is a test of the emergency broadcasting system ' ;
113
- $ result = Cache::write ('other_test ' , $ data );
106
+ $ result = Cache::write ('other_test ' , $ data, ' xcache ' );
114
107
$ this ->assertTrue ($ result );
115
108
116
109
sleep (2 );
117
- $ result = Cache::read ('other_test ' );
110
+ $ result = Cache::read ('other_test ' , ' xcache ' );
118
111
$ this ->assertFalse ($ result );
119
112
120
- Cache::set (array ( 'duration ' => "+1 second " ) );
113
+ Cache::set ([ 'duration ' => "+1 second " ], ' xcache ' );
121
114
122
115
$ data = 'this is a test of the emergency broadcasting system ' ;
123
- $ result = Cache::write ('other_test ' , $ data );
116
+ $ result = Cache::write ('other_test ' , $ data, ' xcache ' );
124
117
$ this ->assertTrue ($ result );
125
118
126
119
sleep (2 );
127
- $ result = Cache::read ('other_test ' );
120
+ $ result = Cache::read ('other_test ' , ' xcache ' );
128
121
$ this ->assertFalse ($ result );
129
122
}
130
123
@@ -135,10 +128,10 @@ public function testExpiry() {
135
128
*/
136
129
public function testDeleteCache () {
137
130
$ data = 'this is a test of the emergency broadcasting system ' ;
138
- $ result = Cache::write ('delete_test ' , $ data );
131
+ $ result = Cache::write ('delete_test ' , $ data, ' xcache ' );
139
132
$ this ->assertTrue ($ result );
140
133
141
- $ result = Cache::delete ('delete_test ' );
134
+ $ result = Cache::delete ('delete_test ' , ' xcache ' );
142
135
$ this ->assertTrue ($ result );
143
136
}
144
137
@@ -149,10 +142,10 @@ public function testDeleteCache() {
149
142
*/
150
143
public function testClearCache () {
151
144
$ data = 'this is a test of the emergency broadcasting system ' ;
152
- $ result = Cache::write ('clear_test_1 ' , $ data );
145
+ $ result = Cache::write ('clear_test_1 ' , $ data, ' xcache ' );
153
146
$ this ->assertTrue ($ result );
154
147
155
- $ result = Cache::write ('clear_test_2 ' , $ data );
148
+ $ result = Cache::write ('clear_test_2 ' , $ data, ' xcache ' );
156
149
$ this ->assertTrue ($ result );
157
150
158
151
$ result = Cache::clear ();
@@ -165,19 +158,19 @@ public function testClearCache() {
165
158
* @return void
166
159
*/
167
160
public function testDecrement () {
168
- $ result = Cache::write ('test_decrement ' , 5 );
161
+ $ result = Cache::write ('test_decrement ' , 5 , ' xcache ' );
169
162
$ this ->assertTrue ($ result );
170
163
171
- $ result = Cache::decrement ('test_decrement ' );
164
+ $ result = Cache::decrement ('test_decrement ' , ' xcache ' );
172
165
$ this ->assertEquals (4 , $ result );
173
166
174
- $ result = Cache::read ('test_decrement ' );
167
+ $ result = Cache::read ('test_decrement ' , ' xcache ' );
175
168
$ this ->assertEquals (4 , $ result );
176
169
177
- $ result = Cache::decrement ('test_decrement ' , 2 );
170
+ $ result = Cache::decrement ('test_decrement ' , 2 , ' xcache ' );
178
171
$ this ->assertEquals (2 , $ result );
179
172
180
- $ result = Cache::read ('test_decrement ' );
173
+ $ result = Cache::read ('test_decrement ' , ' xcache ' );
181
174
$ this ->assertEquals (2 , $ result );
182
175
}
183
176
@@ -187,19 +180,19 @@ public function testDecrement() {
187
180
* @return void
188
181
*/
189
182
public function testIncrement () {
190
- $ result = Cache::write ('test_increment ' , 5 );
183
+ $ result = Cache::write ('test_increment ' , 5 , ' xcache ' );
191
184
$ this ->assertTrue ($ result );
192
185
193
- $ result = Cache::increment ('test_increment ' );
186
+ $ result = Cache::increment ('test_increment ' , ' xcache ' );
194
187
$ this ->assertEquals (6 , $ result );
195
188
196
- $ result = Cache::read ('test_increment ' );
189
+ $ result = Cache::read ('test_increment ' , ' xcache ' );
197
190
$ this ->assertEquals (6 , $ result );
198
191
199
- $ result = Cache::increment ('test_increment ' , 2 );
192
+ $ result = Cache::increment ('test_increment ' , 2 , ' xcache ' );
200
193
$ this ->assertEquals (8 , $ result );
201
194
202
- $ result = Cache::read ('test_increment ' );
195
+ $ result = Cache::read ('test_increment ' , ' xcache ' );
203
196
$ this ->assertEquals (8 , $ result );
204
197
}
205
198
@@ -211,12 +204,12 @@ public function testIncrement() {
211
204
* @return void
212
205
*/
213
206
public function testGroupsReadWrite () {
214
- Cache:: config ( ' xcache_groups ' , array (
207
+ Configure:: write ( ' Cache. xcache_groups ' , [
215
208
'engine ' => 'Xcache ' ,
216
209
'duration ' => 0 ,
217
- 'groups ' => array ( 'group_a ' , 'group_b ' ) ,
210
+ 'groups ' => [ 'group_a ' , 'group_b ' ] ,
218
211
'prefix ' => 'test_ '
219
- ) );
212
+ ] );
220
213
$ this ->assertTrue (Cache::write ('test_groups ' , 'value ' , 'xcache_groups ' ));
221
214
$ this ->assertEquals ('value ' , Cache::read ('test_groups ' , 'xcache_groups ' ));
222
215
@@ -237,12 +230,12 @@ public function testGroupsReadWrite() {
237
230
* @return void
238
231
*/
239
232
public function testGroupDelete () {
240
- Cache:: config ( ' xcache_groups ' , array (
233
+ Configure:: write ( ' Cache. xcache_groups ' , [
241
234
'engine ' => 'Xcache ' ,
242
235
'duration ' => 0 ,
243
- 'groups ' => array ( 'group_a ' , 'group_b ' ) ,
236
+ 'groups ' => [ 'group_a ' , 'group_b ' ] ,
244
237
'prefix ' => 'test_ '
245
- ) );
238
+ ] );
246
239
$ this ->assertTrue (Cache::write ('test_groups ' , 'value ' , 'xcache_groups ' ));
247
240
$ this ->assertEquals ('value ' , Cache::read ('test_groups ' , 'xcache_groups ' ));
248
241
$ this ->assertTrue (Cache::delete ('test_groups ' , 'xcache_groups ' ));
@@ -256,12 +249,12 @@ public function testGroupDelete() {
256
249
* @return void
257
250
**/
258
251
public function testGroupClear () {
259
- Cache:: config ( ' xcache_groups ' , array (
252
+ Configure:: write ( ' Cache. xcache_groups ' , [
260
253
'engine ' => 'Xcache ' ,
261
254
'duration ' => 0 ,
262
- 'groups ' => array ( 'group_a ' , 'group_b ' ) ,
255
+ 'groups ' => [ 'group_a ' , 'group_b ' ] ,
263
256
'prefix ' => 'test_ '
264
- ) );
257
+ ] );
265
258
266
259
$ this ->assertTrue (Cache::write ('test_groups ' , 'value ' , 'xcache_groups ' ));
267
260
$ this ->assertTrue (Cache::clearGroup ('group_a ' , 'xcache_groups ' ));
0 commit comments