[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/cache/tests/cases/ -> lmbCacheTestBase.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  abstract class lmbCacheTestBase extends UnitTestCase
  11  {
  12    var $cache;
  13  
  14    function _createPersisterImp()
  15    {
  16      return null;
  17    }
  18  
  19    function setUp()
  20    {
  21      $this->cache = $this->_createPersisterImp();
  22      $this->cache->flushAll();
  23    }
  24  
  25    function testGetId()
  26    {
  27      $this->assertNotNull($this->cache->getId());
  28    }
  29  
  30    function testGetFalse()
  31    {
  32      $this->_testGetFalse(1);
  33    }
  34  
  35    function testGetTrue()
  36    {
  37      $this->_testGetTrue(1);
  38    }
  39  
  40    function testPutToCache()
  41    {
  42      $this->_testPutToCache(1);
  43    }
  44  
  45    function testPutToCacheWithGroup()
  46    {
  47      $this->_testPutToCacheWithGroup(1);
  48    }
  49  
  50    function testFlushValue()
  51    {
  52      $this->_testFlushValue(1, 2);
  53    }
  54  
  55    function testFlushGroup()
  56    {
  57      $key = 1;
  58      $this->cache->put($key, $v1 = 'value1');
  59      $this->cache->put($key, $v2 = 'value2', 'test-group');
  60  
  61      $this->cache->flushGroup('test-group');
  62  
  63      $this->assertCacheNotValid($this->cache->get($key, 'test-group'));
  64  
  65      $var = $this->cache->get($key);
  66      $this->assertEqual($var, $v1);
  67    }
  68  
  69    function testFlushAll()
  70    {
  71      $this->cache->put(1, $v1 = 'value1');
  72      $this->cache->put(2, $v2 = 'value2');
  73  
  74      $this->cache->flushAll();
  75  
  76      $this->assertCacheNotValid($this->cache->get(1));
  77      $this->assertCacheNotValid($this->cache->get(2));
  78    }
  79  
  80    function _testFlushValue($key1, $key2)
  81    {
  82      $this->cache->put($key1, $v1 = 'value1');
  83      $this->cache->put($key2, $v2 = 'value2');
  84  
  85      $this->cache->flushValue($key1);
  86  
  87      $this->assertCacheNotValid($this->cache->get($key1));
  88  
  89      $cache_value = $this->cache->get($key2);
  90      $this->assertEqual($cache_value, $v2);
  91    }
  92  
  93    function _testGetFalse($key)
  94    {
  95      $this->assertCacheNotValid($this->cache->get($key));
  96    }
  97  
  98    function _testGetTrue($key)
  99    {
 100      $this->cache->put($key, $v = 'value');
 101      $var = $this->cache->get($key);
 102      $this->assertEqual($v, $var);
 103    }
 104  
 105    function _testPutToCache($key)
 106    {
 107      $rnd_key = mt_rand();
 108      $this->cache->put($rnd_key, $v1 = 'value1');
 109  
 110      foreach($this->_getCachedValues() as $v2)
 111      {
 112        $this->cache->put($key, $v2);
 113        $cache_value = $this->cache->get($key);
 114        $this->assertEqual($cache_value, $v2);
 115  
 116        $cache_value = $this->cache->get($rnd_key);
 117        $this->assertEqual($cache_value, $v1);
 118      }
 119    }
 120  
 121    function _testPutToCacheWithGroup($key)
 122    {
 123      $this->cache->put($key, $v1 = 'value1');
 124      $this->cache->put($key, $v2 = 'value2', 'test-group');
 125  
 126      $cache_value = $this->cache->get($key);
 127      $this->assertEqual($cache_value, $v1);
 128  
 129      $cache_value = $this->cache->get($key, 'test-group');
 130      $this->assertEqual($cache_value, $v2);
 131    }
 132  
 133    function _getCachedValues()
 134    {
 135      return array($this->_createNullValue(),
 136                   $this->_createScalarValue(),
 137                   $this->_createArrayValue(),
 138                   $this->_createObjectValue());
 139    }
 140  
 141    function _createNullValue()
 142    {
 143      return null;
 144    }
 145  
 146    function _createScalarValue()
 147    {
 148      return 'some value';
 149    }
 150  
 151    function _createArrayValue()
 152    {
 153      return array('some value');
 154    }
 155  
 156    function _createObjectValue()
 157    {
 158      return new CacheableFooClass();
 159    }
 160  
 161    function assertCacheNotValid($value)
 162    {
 163      $this->assertEqual($value, LIMB_CACHE_NULL_RESULT);
 164    }
 165  }
 166  
 167  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7