CacheTest

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Defined (1)

The class is defined in the following location(s).

/lib/vendor/google/apiclient/tests/general/CacheTest.php  
  1. class CacheTest extends BaseTest { 
  2.  
  3. public function testFile() { 
  4. $dir = sys_get_temp_dir() . '/google-api-php-client/tests'; 
  5. $client = $this->getClient(); 
  6. $client->setClassConfig( 
  7. 'Google_Cache_File',  
  8. 'directory',  
  9. $dir 
  10. ); 
  11. $cache = new Google_Cache_File($client); 
  12. $cache->set('foo', 'bar'); 
  13. $this->assertEquals($cache->get('foo'), 'bar'); 
  14.  
  15. $this->getSetDelete($cache); 
  16.  
  17. public function testNull() 
  18. if (!function_exists('memcache_connect')) { 
  19. $this->markTestSkipped('Test requires memcache'); 
  20. $client = $this->getClient(); 
  21. $cache = new Google_Cache_Null($client); 
  22. $client->setCache($cache); 
  23.  
  24. $cache->set('foo', 'bar'); 
  25. $cache->delete('foo'); 
  26. $this->assertEquals(false, $cache->get('foo')); 
  27.  
  28. $cache->set('foo.1', 'bar.1'); 
  29. $this->assertEquals($cache->get('foo.1'), false); 
  30.  
  31. $cache->set('foo', 'baz'); 
  32. $this->assertEquals($cache->get('foo'), false); 
  33.  
  34. $cache->set('foo', null); 
  35. $cache->delete('foo'); 
  36. $this->assertEquals($cache->get('foo'), false); 
  37.  
  38. public function testMemcache() { 
  39. if (!function_exists('memcache_connect')) { 
  40. $this->markTestSkipped('Test requires memcache'); 
  41. $client = $this->getClient(); 
  42. if (!$client->getClassConfig('Google_Cache_Memcache', 'host')) { 
  43. $this->markTestSkipped('Test requires memcache host specified'); 
  44.  
  45. $cache = new Google_Cache_Memcache($client); 
  46.  
  47. $this->getSetDelete($cache); 
  48.  
  49. public function testAPC() { 
  50. if (!function_exists('apc_add')) { 
  51. $this->markTestSkipped('Test requires APC'); 
  52. if (!ini_get('apc.enable_cli')) { 
  53. $this->markTestSkipped('Test requires APC enabled for CLI'); 
  54. $client = $this->getClient(); 
  55. $cache = new Google_Cache_APC($client); 
  56.  
  57. $this->getSetDelete($cache); 
  58.  
  59. public function getSetDelete($cache) { 
  60. $cache->set('foo', 'bar'); 
  61. $cache->delete('foo'); 
  62. $this->assertEquals(false, $cache->get('foo')); 
  63.  
  64. $cache->set('foo.1', 'bar.1'); 
  65. $cache->delete('foo.1'); 
  66. $this->assertEquals($cache->get('foo.1'), false); 
  67.  
  68. $cache->set('foo', 'baz'); 
  69. $cache->delete('foo'); 
  70. $this->assertEquals($cache->get('foo'), false); 
  71.  
  72. $cache->set('foo', null); 
  73. $cache->delete('foo'); 
  74. $this->assertEquals($cache->get('foo'), false); 
  75.  
  76. $obj = new stdClass(); 
  77. $obj->foo = 'bar'; 
  78. $cache->set('foo', $obj); 
  79. $cache->delete('foo'); 
  80. $this->assertEquals($cache->get('foo'), false); 
  81.  
  82. $cache->set('foo.1', 'bar.1'); 
  83. $this->assertEquals($cache->get('foo.1'), 'bar.1'); 
  84.  
  85. $cache->set('foo', 'baz'); 
  86. $this->assertEquals($cache->get('foo'), 'baz'); 
  87.  
  88. $cache->set('foo', null); 
  89. $this->assertEquals($cache->get('foo'), null); 
  90.  
  91. $cache->set('1/2/3', 'bar'); 
  92. $this->assertEquals($cache->get('1/2/3'), 'bar'); 
  93.  
  94. $obj = new stdClass(); 
  95. $obj->foo = 'bar'; 
  96. $cache->set('foo', $obj); 
  97. $this->assertEquals($cache->get('foo'), $obj);