Skip to content

Commit 92693ab

Browse files
committed
Fix memcache tests.
1 parent 83b4e25 commit 92693ab

File tree

2 files changed

+37
-46
lines changed

2 files changed

+37
-46
lines changed

lib/Cake/Cache/Engine/MemcacheEngine.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22
/**
3-
* Memcache storage engine for cache
4-
*
5-
*
6-
* PHP 5
7-
*
83
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
94
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
105
*
@@ -13,11 +8,11 @@
138
*
149
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
1510
* @link http://cakephp.org CakePHP(tm) Project
16-
* @package Cake.Cache.Engine
1711
* @since CakePHP(tm) v 1.2.0.4933
1812
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1913
*/
2014
namespace Cake\Cache\Engine;
15+
2116
use Cake\Cache\CacheEngine;
2217
use Cake\Error;
2318
use Cake\Utility\Inflector;

lib/Cake/Test/TestCase/Cache/Engine/MemcacheEngineTest.php

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
<?php
22
/**
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>
84
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
95
*
106
* Licensed under The MIT License
117
* Redistributions of files must retain the above copyright notice
128
*
139
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
1410
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
15-
* @package Cake.Test.Case.Cache.Engine
1611
* @since CakePHP(tm) v 1.2.0.5434
1712
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1813
*/
1914
namespace Cake\Test\TestCase\Cache\Engine;
15+
2016
use Cake\Cache\Cache;
2117
use Cake\Cache\Engine\MemcacheEngine;
2218
use Cake\Core\Configure;
2319
use Cake\TestSuite\TestCase;
2420

21+
/**
22+
* @package Cake.Test.TestCase.Cache.Engine
23+
*/
2524
class TestMemcacheEngine extends MemcacheEngine {
2625

2726
/**
@@ -43,7 +42,7 @@ public function setMemcache($memcache) {
4342
/**
4443
* MemcacheEngineTest class
4544
*
46-
* @package Cake.Test.Case.Cache.Engine
45+
* @package Cake.Test.TestCase.Cache.Engine
4746
*/
4847
class MemcacheEngineTest extends TestCase {
4948

@@ -56,9 +55,8 @@ public function setUp() {
5655
parent::setUp();
5756
$this->skipIf(!class_exists('Memcache'), 'Memcache is not installed or configured properly.');
5857

59-
$this->_cacheDisable = Configure::read('Cache.disable');
6058
Configure::write('Cache.disable', false);
61-
Cache::config('memcache', array(
59+
Configure::write('Cache.memcache', array(
6260
'engine' => 'Memcache',
6361
'prefix' => 'cake_',
6462
'duration' => 3600
@@ -72,11 +70,9 @@ public function setUp() {
7270
*/
7371
public function tearDown() {
7472
parent::tearDown();
75-
Configure::write('Cache.disable', $this->_cacheDisable);
7673
Cache::drop('memcache');
7774
Cache::drop('memcache_groups');
7875
Cache::drop('memcache_helper');
79-
Cache::config('default');
8076
}
8177

8278
/**
@@ -190,8 +186,6 @@ public function testParseServerStringUnix() {
190186
* @return void
191187
*/
192188
public function testReadAndWriteCache() {
193-
Cache::set(array('duration' => 1), null, 'memcache');
194-
195189
$result = Cache::read('test', 'memcache');
196190
$expecting = '';
197191
$this->assertEquals($expecting, $result);
@@ -213,7 +207,7 @@ public function testReadAndWriteCache() {
213207
* @return void
214208
*/
215209
public function testExpiry() {
216-
Cache::set(array('duration' => 1), 'memcache');
210+
Cache::set(['duration' => 1], 'memcache');
217211

218212
$result = Cache::read('test', 'memcache');
219213
$this->assertFalse($result);
@@ -226,7 +220,7 @@ public function testExpiry() {
226220
$result = Cache::read('other_test', 'memcache');
227221
$this->assertFalse($result);
228222

229-
Cache::set(array('duration' => "+1 second"), 'memcache');
223+
Cache::set(['duration' => "+1 second"], 'memcache');
230224

231225
$data = 'this is a test of the emergency broadcasting system';
232226
$result = Cache::write('other_test', $data, 'memcache');
@@ -236,13 +230,13 @@ public function testExpiry() {
236230
$result = Cache::read('other_test', 'memcache');
237231
$this->assertFalse($result);
238232

239-
Cache::config('memcache', array('duration' => '+1 second'));
233+
Cache::set(['duration' => '+1 second'], 'memcache');
240234
sleep(2);
241235

242236
$result = Cache::read('other_test', 'memcache');
243237
$this->assertFalse($result);
244238

245-
Cache::config('memcache', array('duration' => '+29 days'));
239+
Cache::set(['duration' => '+29 days'], 'memcache');
246240
$data = 'this is a test of the emergency broadcasting system';
247241
$result = Cache::write('long_expiry_test', $data, 'memcache');
248242
$this->assertTrue($result);
@@ -251,8 +245,6 @@ public function testExpiry() {
251245
$result = Cache::read('long_expiry_test', 'memcache');
252246
$expecting = $data;
253247
$this->assertEquals($expecting, $result);
254-
255-
Cache::config('memcache', array('duration' => 3600));
256248
}
257249

258250
/**
@@ -319,17 +311,17 @@ public function testIncrement() {
319311
* @return void
320312
*/
321313
public function testConfigurationConflict() {
322-
Cache::config('long_memcache', array(
314+
Configure::write('Cache.long_memcache', [
323315
'engine' => 'Memcache',
324316
'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', [
328320
'engine' => 'Memcache',
329321
'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']);
333325

334326
$this->assertTrue(Cache::write('duration_test', 'yay', 'long_memcache'));
335327
$this->assertTrue(Cache::write('short_duration_test', 'boo', 'short_memcache'));
@@ -354,11 +346,11 @@ public function testConfigurationConflict() {
354346
* @return void
355347
*/
356348
public function testClear() {
357-
Cache::config('memcache2', array(
349+
Configure::write('Cache.memcache2', [
358350
'engine' => 'Memcache',
359351
'prefix' => 'cake2_',
360352
'duration' => 3600
361-
));
353+
]);
362354

363355
Cache::write('some_value', 'cache1', 'memcache');
364356
$result = Cache::clear(true, 'memcache');
@@ -380,7 +372,11 @@ public function testClear() {
380372
* @return void
381373
*/
382374
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+
]);
384380
$result = Cache::write('test_key', 'written!', 'memcache');
385381

386382
$this->assertTrue($result);
@@ -415,17 +411,17 @@ public function testLongDurationEqualToZero() {
415411
* @return void
416412
*/
417413
public function testGroupReadWrite() {
418-
Cache::config('memcache_groups', array(
414+
Configure::write('Cache.memcache_groups', [
419415
'engine' => 'Memcache',
420416
'duration' => 3600,
421-
'groups' => array('group_a', 'group_b'),
417+
'groups' => ['group_a', 'group_b'],
422418
'prefix' => 'test_'
423-
));
424-
Cache::config('memcache_helper', array(
419+
]);
420+
Configure::write('Cache.memcache_helper', [
425421
'engine' => 'Memcache',
426422
'duration' => 3600,
427423
'prefix' => 'test_'
428-
));
424+
]);
429425
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
430426
$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups'));
431427

@@ -446,11 +442,11 @@ public function testGroupReadWrite() {
446442
* @return void
447443
*/
448444
public function testGroupDelete() {
449-
Cache::config('memcache_groups', array(
445+
Configure::write('Cache.memcache_groups', [
450446
'engine' => 'Memcache',
451447
'duration' => 3600,
452-
'groups' => array('group_a', 'group_b')
453-
));
448+
'groups' => ['group_a', 'group_b']
449+
]);
454450
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
455451
$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups'));
456452
$this->assertTrue(Cache::delete('test_groups', 'memcache_groups'));
@@ -464,11 +460,11 @@ public function testGroupDelete() {
464460
* @return void
465461
**/
466462
public function testGroupClear() {
467-
Cache::config('memcache_groups', array(
463+
Configure::write('Cache.memcache_groups', [
468464
'engine' => 'Memcache',
469465
'duration' => 3600,
470-
'groups' => array('group_a', 'group_b')
471-
));
466+
'groups' => ['group_a', 'group_b']
467+
]);
472468

473469
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
474470
$this->assertTrue(Cache::clearGroup('group_a', 'memcache_groups'));

0 commit comments

Comments
 (0)