Esempio n. 1
0
 protected function getPool()
 {
     try {
         $pool = \Hoard\CacheManager::getPool('test.simple');
         $pool->clear();
         return $pool;
     } catch (\Exception $e) {
         if ($e->getMessage() == 'Memcached extension is not installed.') {
             $this->markTestSkipped();
         }
         throw $e;
     }
 }
Esempio n. 2
0
 public function setUp()
 {
     parent::setUp();
     // get pools
     $this->parentPool = \Hoard\CacheManager::getPool('test.memcached');
     $this->childPool = \Hoard\CacheManager::getPool('test.memcached.child_pool');
     try {
         // test for extension
         $this->parentPool->getItem('doesnt_exist');
     } catch (\Exception $e) {
         if ($e->getMessage() == 'Memcached extension is not installed.') {
             $this->markTestSkipped();
         }
         throw $e;
     }
     // rather than getting blank pools, we want to ensure existing data
     // stays in there and we use non-colliding keys
     $this->key = md5(rand() . time());
 }
Esempio n. 3
0
 /**
  * This is quite simple, we swap out whatever adapter is normally used by
  * the pool with the transient adapter and prepopulate the items.
  * @param array $items Items to be prepopulated in the pool.
  * @param string $poolName If you provide a pool name then the mocked pool
  * returned will contain all the same business logic.
  */
 public function getMockedPool(array $items = array(), $poolName = '')
 {
     // this is quite simple, we swap out whatever adapter is normally used
     // by the pool with the transient adapter
     $adapter = new \Hoard\Adapter\Transient();
     // get the class name for the pool
     if (empty($poolName)) {
         $className = 'Hoard\\GenericPool';
     } else {
         $className = \Hoard\CacheManager::getClassFromPoolName($poolName);
     }
     // mock the original business logic
     $mock = $this->getMock($className, null);
     $mock->setAdapter($adapter);
     $adapter->setPool($mock);
     // load in the items
     foreach ($items as $key => $value) {
         $item = $mock->getItem($key);
         $item->set($value);
     }
     return $mock;
 }
Esempio n. 4
0
 protected function getPool()
 {
     $pool = \Hoard\CacheManager::getPool('test.redis');
     $pool->clear();
     return $pool;
 }