| 1 |
<?php |
| 2 |
/** |
| 3 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
* or more contributor license agreements. See the NOTICE file |
| 5 |
* distributed with this work for additional information |
| 6 |
* regarding copyright ownership. The ASF licenses this file |
| 7 |
* to you under the Apache License, Version 2.0 (the |
| 8 |
* "License"); you may not use this file except in compliance |
| 9 |
* with the License. You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, |
| 14 |
* software distributed under the License is distributed on an |
| 15 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
* KIND, either express or implied. See the License for the |
| 17 |
* specific language governing permissions and limitations |
| 18 |
* under the License. |
| 19 |
*/ |
| 20 |
|
| 21 |
class CacheTest extends BaseTest |
| 22 |
{ |
| 23 |
public function testFile() |
| 24 |
{ |
| 25 |
$dir = sys_get_temp_dir() . '/google-api-php-client/tests'; |
| 26 |
$client = $this->getClient(); |
| 27 |
$client->setClassConfig( |
| 28 |
'Google_Cache_File', |
| 29 |
'directory', |
| 30 |
$dir |
| 31 |
); |
| 32 |
$cache = new Google_Cache_File($client); |
| 33 |
$cache->set('foo', 'bar'); |
| 34 |
$this->assertEquals($cache->get('foo'), 'bar'); |
| 35 |
|
| 36 |
$this->getSetDelete($cache); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @requires extension Memcache |
| 41 |
*/ |
| 42 |
public function testNull() |
| 43 |
{ |
| 44 |
$client = $this->getClient(); |
| 45 |
$cache = new Google_Cache_Null($client); |
| 46 |
$client->setCache($cache); |
| 47 |
|
| 48 |
$cache->set('foo', 'bar'); |
| 49 |
$cache->delete('foo'); |
| 50 |
$this->assertEquals(false, $cache->get('foo')); |
| 51 |
|
| 52 |
$cache->set('foo.1', 'bar.1'); |
| 53 |
$this->assertEquals($cache->get('foo.1'), false); |
| 54 |
|
| 55 |
$cache->set('foo', 'baz'); |
| 56 |
$this->assertEquals($cache->get('foo'), false); |
| 57 |
|
| 58 |
$cache->set('foo', null); |
| 59 |
$cache->delete('foo'); |
| 60 |
$this->assertEquals($cache->get('foo'), false); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* @requires extension Memcache |
| 65 |
*/ |
| 66 |
public function testMemcache() |
| 67 |
{ |
| 68 |
$client = $this->getClient(); |
| 69 |
if (!$client->getClassConfig('Google_Cache_Memcache', 'host')) { |
| 70 |
$this->markTestSkipped('Test requires memcache host specified'); |
| 71 |
} |
| 72 |
|
| 73 |
$cache = new Google_Cache_Memcache($client); |
| 74 |
|
| 75 |
$this->getSetDelete($cache); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @requires extension APC |
| 80 |
*/ |
| 81 |
public function testAPC() |
| 82 |
{ |
| 83 |
if (!ini_get('apc.enable_cli')) { |
| 84 |
$this->markTestSkipped('Test requires APC enabled for CLI'); |
| 85 |
} |
| 86 |
$client = $this->getClient(); |
| 87 |
$cache = new Google_Cache_Apc($client); |
| 88 |
|
| 89 |
$this->getSetDelete($cache); |
| 90 |
} |
| 91 |
|
| 92 |
public function getSetDelete($cache) |
| 93 |
{ |
| 94 |
$cache->set('foo', 'bar'); |
| 95 |
$cache->delete('foo'); |
| 96 |
$this->assertEquals(false, $cache->get('foo')); |
| 97 |
|
| 98 |
$cache->set('foo.1', 'bar.1'); |
| 99 |
$cache->delete('foo.1'); |
| 100 |
$this->assertEquals($cache->get('foo.1'), false); |
| 101 |
|
| 102 |
$cache->set('foo', 'baz'); |
| 103 |
$cache->delete('foo'); |
| 104 |
$this->assertEquals($cache->get('foo'), false); |
| 105 |
|
| 106 |
$cache->set('foo', null); |
| 107 |
$cache->delete('foo'); |
| 108 |
$this->assertEquals($cache->get('foo'), false); |
| 109 |
|
| 110 |
$obj = new stdClass(); |
| 111 |
$obj->foo = 'bar'; |
| 112 |
$cache->set('foo', $obj); |
| 113 |
$cache->delete('foo'); |
| 114 |
$this->assertEquals($cache->get('foo'), false); |
| 115 |
|
| 116 |
$cache->set('foo.1', 'bar.1'); |
| 117 |
$this->assertEquals($cache->get('foo.1'), 'bar.1'); |
| 118 |
|
| 119 |
$cache->set('foo', 'baz'); |
| 120 |
$this->assertEquals($cache->get('foo'), 'baz'); |
| 121 |
|
| 122 |
$cache->set('foo', null); |
| 123 |
$this->assertEquals($cache->get('foo'), null); |
| 124 |
|
| 125 |
$cache->set('1/2/3', 'bar'); |
| 126 |
$this->assertEquals($cache->get('1/2/3'), 'bar'); |
| 127 |
|
| 128 |
$obj = new stdClass(); |
| 129 |
$obj->foo = 'bar'; |
| 130 |
$cache->set('foo', $obj); |
| 131 |
$this->assertEquals($cache->get('foo'), $obj); |
| 132 |
} |
| 133 |
} |
| 134 |
|