示例#1
0
 public function testConstructionOptions()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $options['servers'][] = array('127.0.0.1', '11211', '50');
     $options['servers'][] = array('127.0.0.1', '11211');
     $options['extension'] = $this->extension;
     $driver = new ehough_stash_driver_Memcache();
     $driver->setOptions($options);
     $item = new ehough_stash_Item();
     $poolStub = new ehough_stash_test_stub_PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item->setPool($poolStub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store memcache driver using multiple servers');
     $options = array();
     $options['extension'] = $this->extension;
     $driver = new ehough_stash_driver_Memcache();
     $driver->setOptions($options);
     $item = new ehough_stash_Item();
     $poolStub = new ehough_stash_test_stub_PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item->setPool($poolStub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store memcache driver using default server');
 }
示例#2
0
 public function testSet()
 {
     $item = new ehough_stash_Item();
     $poolStub = new ehough_stash_test_stub_PoolGetDriverStub();
     $poolStub->setDriver(new ehough_stash_test_stub_DriverExceptionStub());
     $item->setPool($poolStub);
     $item->setKey(array('path', 'to', 'store'));
     $this->assertFalse($item->isDisabled());
     $this->assertFalse($item->set(array(1, 2, 3), 3600));
     $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
 }
示例#3
0
 public function testConstruction()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $driver = new ehough_stash_driver_Sqlite();
     $driver->setOptions($options);
     $item = new ehough_stash_Item();
     $poolSub = new ehough_stash_test_stub_PoolGetDriverStub();
     $poolSub->setDriver($driver);
     $item->setPool($poolSub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store with unconfigured extension.');
 }
示例#4
0
 public function testKeyCollisions2()
 {
     $driver = new $this->driverClass();
     $poolStub = new ehough_stash_test_stub_PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item1 = new ehough_stash_Item();
     $item1->setPool($poolStub);
     $item1->setKey(array('#'));
     $item1->set('X');
     $item2 = new ehough_stash_Item();
     $item2->setPool($poolStub);
     $item2->setKey(array(':'));
     $item2->set('Y');
     $this->assertEquals('X', $item1->get());
 }
示例#5
0
 /**
  * Test that the paths are created using the key hash function.
  */
 public function testOptionKeyHashFunctionDirs()
 {
     $hashfunctions = array('ehough_stash_test_driver_FileSystemTest_strdup', 'strrev', 'md5', array($this, '__callback_testOptionKeyHashFunctionDirs'));
     $paths = array('one', 'two', 'three', 'four');
     foreach ($hashfunctions as $hashfunction) {
         $driver = new ehough_stash_driver_FileSystem();
         $driver->setOptions($this->getOptions(array('keyHashFunction' => $hashfunction, 'path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'stash', 'dirSplit' => 1)));
         $rand = str_repeat(uniqid(), 32);
         $item = new ehough_stash_Item();
         $poolStub = new ehough_stash_test_stub_PoolGetDriverStub();
         $poolStub->setDriver($driver);
         $item->setPool($poolStub);
         $item->setKey($paths);
         $item->set($rand);
         $allpaths = array_merge(array('cache'), $paths);
         $predicted = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'stash' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array_map($hashfunction, $allpaths)) . $this->extension;
         $this->assertFileExists($predicted);
     }
 }