1
1
<?php
2
2
/**
3
- * MemcacheEngineTest 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 \Cache \Engine \MemcacheEngine ;
22
18
use Cake \Core \Configure ;
23
19
use Cake \TestSuite \TestCase ;
24
20
21
+ /**
22
+ * @package Cake.Test.TestCase.Cache.Engine
23
+ */
25
24
class TestMemcacheEngine extends MemcacheEngine {
26
25
27
26
/**
@@ -43,7 +42,7 @@ public function setMemcache($memcache) {
43
42
/**
44
43
* MemcacheEngineTest class
45
44
*
46
- * @package Cake.Test.Case .Cache.Engine
45
+ * @package Cake.Test.TestCase .Cache.Engine
47
46
*/
48
47
class MemcacheEngineTest extends TestCase {
49
48
@@ -56,9 +55,8 @@ public function setUp() {
56
55
parent ::setUp ();
57
56
$ this ->skipIf (!class_exists ('Memcache ' ), 'Memcache is not installed or configured properly. ' );
58
57
59
- $ this ->_cacheDisable = Configure::read ('Cache.disable ' );
60
58
Configure::write ('Cache.disable ' , false );
61
- Cache:: config ( ' memcache ' , array (
59
+ Configure:: write ( ' Cache. memcache ' , array (
62
60
'engine ' => 'Memcache ' ,
63
61
'prefix ' => 'cake_ ' ,
64
62
'duration ' => 3600
@@ -72,11 +70,9 @@ public function setUp() {
72
70
*/
73
71
public function tearDown () {
74
72
parent ::tearDown ();
75
- Configure::write ('Cache.disable ' , $ this ->_cacheDisable );
76
73
Cache::drop ('memcache ' );
77
74
Cache::drop ('memcache_groups ' );
78
75
Cache::drop ('memcache_helper ' );
79
- Cache::config ('default ' );
80
76
}
81
77
82
78
/**
@@ -190,8 +186,6 @@ public function testParseServerStringUnix() {
190
186
* @return void
191
187
*/
192
188
public function testReadAndWriteCache () {
193
- Cache::set (array ('duration ' => 1 ), null , 'memcache ' );
194
-
195
189
$ result = Cache::read ('test ' , 'memcache ' );
196
190
$ expecting = '' ;
197
191
$ this ->assertEquals ($ expecting , $ result );
@@ -213,7 +207,7 @@ public function testReadAndWriteCache() {
213
207
* @return void
214
208
*/
215
209
public function testExpiry () {
216
- Cache::set (array ( 'duration ' => 1 ) , 'memcache ' );
210
+ Cache::set ([ 'duration ' => 1 ] , 'memcache ' );
217
211
218
212
$ result = Cache::read ('test ' , 'memcache ' );
219
213
$ this ->assertFalse ($ result );
@@ -226,7 +220,7 @@ public function testExpiry() {
226
220
$ result = Cache::read ('other_test ' , 'memcache ' );
227
221
$ this ->assertFalse ($ result );
228
222
229
- Cache::set (array ( 'duration ' => "+1 second " ) , 'memcache ' );
223
+ Cache::set ([ 'duration ' => "+1 second " ] , 'memcache ' );
230
224
231
225
$ data = 'this is a test of the emergency broadcasting system ' ;
232
226
$ result = Cache::write ('other_test ' , $ data , 'memcache ' );
@@ -236,13 +230,13 @@ public function testExpiry() {
236
230
$ result = Cache::read ('other_test ' , 'memcache ' );
237
231
$ this ->assertFalse ($ result );
238
232
239
- Cache::config ( ' memcache ' , array ( ' duration ' => '+1 second ' ) );
233
+ Cache::set ([ ' duration ' => '+1 second ' ], ' memcache ' );
240
234
sleep (2 );
241
235
242
236
$ result = Cache::read ('other_test ' , 'memcache ' );
243
237
$ this ->assertFalse ($ result );
244
238
245
- Cache::config ( ' memcache ' , array ( ' duration ' => '+29 days ' ) );
239
+ Cache::set ([ ' duration ' => '+29 days ' ], ' memcache ' );
246
240
$ data = 'this is a test of the emergency broadcasting system ' ;
247
241
$ result = Cache::write ('long_expiry_test ' , $ data , 'memcache ' );
248
242
$ this ->assertTrue ($ result );
@@ -251,8 +245,6 @@ public function testExpiry() {
251
245
$ result = Cache::read ('long_expiry_test ' , 'memcache ' );
252
246
$ expecting = $ data ;
253
247
$ this ->assertEquals ($ expecting , $ result );
254
-
255
- Cache::config ('memcache ' , array ('duration ' => 3600 ));
256
248
}
257
249
258
250
/**
@@ -319,17 +311,17 @@ public function testIncrement() {
319
311
* @return void
320
312
*/
321
313
public function testConfigurationConflict () {
322
- Cache:: config ( ' long_memcache ' , array (
314
+ Configure:: write ( ' Cache. long_memcache ' , [
323
315
'engine ' => 'Memcache ' ,
324
316
'duration ' => '+2 seconds ' ,
325
- 'servers ' => array ( '127.0.0.1:11211 ' ) ,
326
- ) );
327
- Cache:: config ( ' short_memcache ' , array (
317
+ 'servers ' => [ '127.0.0.1:11211 ' ] ,
318
+ ] );
319
+ Configure:: write ( ' Cache. short_memcache ' , [
328
320
'engine ' => 'Memcache ' ,
329
321
'duration ' => '+1 seconds ' ,
330
- 'servers ' => array ( '127.0.0.1:11211 ' ) ,
331
- ) );
332
- Cache:: config ( ' some_file ' , array ( 'engine ' => 'File ' ) );
322
+ 'servers ' => [ '127.0.0.1:11211 ' ] ,
323
+ ] );
324
+ Configure:: write ( ' Cache. some_file ' , [ 'engine ' => 'File ' ] );
333
325
334
326
$ this ->assertTrue (Cache::write ('duration_test ' , 'yay ' , 'long_memcache ' ));
335
327
$ this ->assertTrue (Cache::write ('short_duration_test ' , 'boo ' , 'short_memcache ' ));
@@ -354,11 +346,11 @@ public function testConfigurationConflict() {
354
346
* @return void
355
347
*/
356
348
public function testClear () {
357
- Cache:: config ( ' memcache2 ' , array (
349
+ Configure:: write ( ' Cache. memcache2 ' , [
358
350
'engine ' => 'Memcache ' ,
359
351
'prefix ' => 'cake2_ ' ,
360
352
'duration ' => 3600
361
- ) );
353
+ ] );
362
354
363
355
Cache::write ('some_value ' , 'cache1 ' , 'memcache ' );
364
356
$ result = Cache::clear (true , 'memcache ' );
@@ -380,7 +372,11 @@ public function testClear() {
380
372
* @return void
381
373
*/
382
374
public function testZeroDuration () {
383
- Cache::config ('memcache ' , array ('duration ' => 0 ));
375
+ Configure::write ('Cache.memcache ' , [
376
+ 'engine ' => 'Memcache ' ,
377
+ 'prefix ' => 'cake_ ' ,
378
+ 'duration ' => 0
379
+ ]);
384
380
$ result = Cache::write ('test_key ' , 'written! ' , 'memcache ' );
385
381
386
382
$ this ->assertTrue ($ result );
@@ -415,17 +411,17 @@ public function testLongDurationEqualToZero() {
415
411
* @return void
416
412
*/
417
413
public function testGroupReadWrite () {
418
- Cache:: config ( ' memcache_groups ' , array (
414
+ Configure:: write ( ' Cache. memcache_groups ' , [
419
415
'engine ' => 'Memcache ' ,
420
416
'duration ' => 3600 ,
421
- 'groups ' => array ( 'group_a ' , 'group_b ' ) ,
417
+ 'groups ' => [ 'group_a ' , 'group_b ' ] ,
422
418
'prefix ' => 'test_ '
423
- ) );
424
- Cache:: config ( ' memcache_helper ' , array (
419
+ ] );
420
+ Configure:: write ( ' Cache. memcache_helper ' , [
425
421
'engine ' => 'Memcache ' ,
426
422
'duration ' => 3600 ,
427
423
'prefix ' => 'test_ '
428
- ) );
424
+ ] );
429
425
$ this ->assertTrue (Cache::write ('test_groups ' , 'value ' , 'memcache_groups ' ));
430
426
$ this ->assertEquals ('value ' , Cache::read ('test_groups ' , 'memcache_groups ' ));
431
427
@@ -446,11 +442,11 @@ public function testGroupReadWrite() {
446
442
* @return void
447
443
*/
448
444
public function testGroupDelete () {
449
- Cache:: config ( ' memcache_groups ' , array (
445
+ Configure:: write ( ' Cache. memcache_groups ' , [
450
446
'engine ' => 'Memcache ' ,
451
447
'duration ' => 3600 ,
452
- 'groups ' => array ( 'group_a ' , 'group_b ' )
453
- ) );
448
+ 'groups ' => [ 'group_a ' , 'group_b ' ]
449
+ ] );
454
450
$ this ->assertTrue (Cache::write ('test_groups ' , 'value ' , 'memcache_groups ' ));
455
451
$ this ->assertEquals ('value ' , Cache::read ('test_groups ' , 'memcache_groups ' ));
456
452
$ this ->assertTrue (Cache::delete ('test_groups ' , 'memcache_groups ' ));
@@ -464,11 +460,11 @@ public function testGroupDelete() {
464
460
* @return void
465
461
**/
466
462
public function testGroupClear () {
467
- Cache:: config ( ' memcache_groups ' , array (
463
+ Configure:: write ( ' Cache. memcache_groups ' , [
468
464
'engine ' => 'Memcache ' ,
469
465
'duration ' => 3600 ,
470
- 'groups ' => array ( 'group_a ' , 'group_b ' )
471
- ) );
466
+ 'groups ' => [ 'group_a ' , 'group_b ' ]
467
+ ] );
472
468
473
469
$ this ->assertTrue (Cache::write ('test_groups ' , 'value ' , 'memcache_groups ' ));
474
470
$ this ->assertTrue (Cache::clearGroup ('group_a ' , 'memcache_groups ' ));
0 commit comments