setKey() public method

public setKey ( array $key, $namespace = null )
$key array
 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 Memcache();
     $driver->setOptions($options);
     $item = new Item();
     $poolStub = new 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 Memcache();
     $driver->setOptions($options);
     $item = new Item();
     $poolStub = new 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');
 }
Exemplo n.º 2
0
 public function testClear()
 {
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver(new DriverExceptionStub());
     $item->setPool($poolStub);
     $item->setKey(array('path', 'to', 'clear'));
     $this->assertFalse($item->isDisabled());
     $this->assertFalse($item->clear());
     $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
 }
Exemplo n.º 3
0
 public function testConstruction()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $driver = new Sqlite();
     $driver->setOptions($options);
     $item = new Item();
     $poolSub = new PoolGetDriverStub();
     $poolSub->setDriver($driver);
     $item->setPool($poolSub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store with unconfigured extension.');
 }
Exemplo n.º 4
0
 public function testConstruction()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $options['servers'][] = array('127.0.0.1', '11211', '50');
     $driver = new Memcache($options);
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item->setPool($poolStub);
     $item->setKey($key);
     $this->assertTrue($item->set($key)->save(), 'Able to load and store with unconfigured extension.');
 }
Exemplo n.º 5
0
 protected function getItem($key, $exceptionDriver = false)
 {
     if ($exceptionDriver) {
         $fullDriver = 'Stash\\Test\\Stubs\\DriverExceptionStub';
     } else {
         $fullDriver = 'Stash\\Driver\\Ephemeral';
     }
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver(new $fullDriver());
     $item->setPool($poolStub);
     $item->setKey($key);
     return $item;
 }
Exemplo n.º 6
0
 public function testKeyCollisions2()
 {
     $driver = new $this->driverClass();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item1 = new Item();
     $item1->setPool($poolStub);
     $item1->setKey(array('#'));
     $item1->set('X');
     $item2 = new Item();
     $item2->setPool($poolStub);
     $item2->setKey(array(':'));
     $item2->set('Y');
     $this->assertEquals('X', $item1->get());
 }
Exemplo n.º 7
0
 /**
  * Test that the paths are created using the key hash function.
  */
 public function testOptionKeyHashFunctionDirs()
 {
     $hashfunctions = array('Stash\\Test\\Driver\\strdup', 'strrev', 'md5', function ($value) {
         return abs(crc32($value));
     });
     $paths = array('one', 'two', 'three', 'four');
     foreach ($hashfunctions as $hashfunction) {
         $driver = new FileSystem($this->getOptions(array('keyHashFunction' => $hashfunction, 'path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'stash', 'dirSplit' => 1)));
         $rand = str_repeat(uniqid(), 32);
         $item = new Item();
         $poolStub = new PoolGetDriverStub();
         $poolStub->setDriver($driver);
         $item->setPool($poolStub);
         $item->setKey($paths);
         $item->set($rand)->save();
         $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);
     }
 }