コード例 #1
0
 public function testFirstWorkingAdapter()
 {
     $data = new \Itkg\Core\Cache\CacheableData('my_key', null, array('values'));
     $stub = $this->getMock('Itkg\\Core\\Cache\\Adapter\\Redis', array(), array(array()));
     $stub->expects($this->once())->method('get')->with($data);
     $stub->expects($this->once())->method('set')->with($data);
     $secondStub = $this->getMock('Itkg\\Core\\Cache\\Adapter\\Redis', array(), array(array()));
     $secondStub->expects($this->never())->method('get');
     $secondStub->expects($this->never())->method('set');
     $adapters = array($stub, $secondStub);
     $chain = new \Itkg\Core\Cache\Adapter\Chain($adapters);
     $chain->get($data);
     $chain->set($data);
 }
コード例 #2
0
ファイル: ChainTest.php プロジェクト: itkg/core
 public function testGetSetRemoveAndRemoveAll()
 {
     $data = new \Itkg\Core\Cache\CacheableData('my_key', null, array('values'));
     $adapters = array($this->getMock('Itkg\\Core\\Cache\\Adapter\\Redis', array(), array(array())));
     $strategy = $this->getMock('Itkg\\Core\\Cache\\Adapter\\Chain\\UseFirstWorkingStrategy');
     $strategy->expects($this->once())->method('get')->with($adapters, $data);
     $strategy->expects($this->once())->method('set')->with($adapters, $data);
     $strategy->expects($this->once())->method('remove')->with($adapters, $data);
     $strategy->expects($this->once())->method('get')->with($adapters);
     $chain = new \Itkg\Core\Cache\Adapter\Chain($adapters, $strategy);
     $chain->set($data);
     $chain->get($data);
     $chain->remove($data);
     $chain->removeAll();
 }
コード例 #3
0
ファイル: UseAllStrategyTest.php プロジェクト: itkg/core
 public function testGetSetRemoveAndRemoveAll()
 {
     $data = new \Itkg\Core\Cache\CacheableData('my_key', null, array('values'));
     $stub = $this->getMock('Itkg\\Core\\Cache\\Adapter\\Redis', array(), array(array()));
     $stub->expects($this->once())->method('get')->with($data)->will($this->returnValue('yeah!'));
     $stub->expects($this->once())->method('set')->with($data);
     $stub->expects($this->once())->method('remove')->with($data);
     $stub->expects($this->once())->method('removeAll');
     $secondStub = $this->getMock('Itkg\\Core\\Cache\\Adapter\\Redis', array(), array(array()));
     $secondStub->expects($this->never())->method('get');
     $secondStub->expects($this->once())->method('set');
     $secondStub->expects($this->once())->method('remove')->with($data);
     $secondStub->expects($this->once())->method('removeAll');
     $adapters = array($stub, $secondStub);
     $chain = new \Itkg\Core\Cache\Adapter\Chain($adapters, new \Itkg\Core\Cache\Adapter\Chain\UseAllStrategy());
     $chain->get($data);
     $chain->set($data);
     $chain->remove($data);
     $chain->removeAll();
 }