/**
  * Set up test case
  *
  * @return void
  */
 public function setUp()
 {
     $phpredisVersion = phpversion('redis');
     if (version_compare($phpredisVersion, '1.2.0', '<')) {
         $this->markTestSkipped(sprintf('phpredis extension version %s is not supported. Please update to verson 1.2.0+.', $phpredisVersion));
     }
     try {
         if (!@fsockopen('127.0.0.1', 6379)) {
             $this->markTestSkipped('redis server not reachable');
         }
     } catch (\Exception $e) {
         $this->markTestSkipped('redis server not reachable');
     }
     $this->backend = new RedisBackend(new EnvironmentConfiguration('Redis a wonderful color Testing', '/some/path', PHP_MAXPATHLEN), ['hostname' => '127.0.0.1', 'database' => 0]);
     $this->cache = $this->createMock(FrontendInterface::class);
     $this->cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('TestCache'));
     $this->backend->setCache($this->cache);
     $this->backend->flush();
 }
 /**
  * @test
  */
 public function flushRemovesAllCacheEntries()
 {
     $this->mockCacheFrontend->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
     $entryIdentifier1 = 'SimpleFileBackendTest1';
     $pathAndFilename1 = 'vfs://Temporary/Directory/Cache/Data/UnitTestCache/' . $entryIdentifier1;
     $entryIdentifier2 = 'SimpleFileBackendTest2';
     $pathAndFilename2 = 'vfs://Temporary/Directory/Cache/Data/UnitTestCache/' . $entryIdentifier2;
     $simpleFileBackend = $this->getSimpleFileBackend();
     $simpleFileBackend->set($entryIdentifier1, 'some data');
     $simpleFileBackend->set($entryIdentifier2, 'some more data');
     $this->assertFileExists($pathAndFilename1);
     $this->assertFileExists($pathAndFilename2);
     $this->assertTrue($simpleFileBackend->has($entryIdentifier1));
     $this->assertTrue($simpleFileBackend->has($entryIdentifier2));
     $simpleFileBackend->flush();
     $this->assertFileNotExists($pathAndFilename1);
     $this->assertFalse($simpleFileBackend->has($entryIdentifier1));
     $this->assertFileNotExists($pathAndFilename2);
     $this->assertFalse($simpleFileBackend->has($entryIdentifier2));
 }
Example #3
0
 /**
  * Registers a cache so it can be retrieved at a later point.
  *
  * @param FrontendInterface $cache The cache frontend to be registered
  * @param bool $persistent
  * @return void
  * @throws DuplicateIdentifierException if a cache with the given identifier has already been registered.
  * @api
  */
 public function registerCache(FrontendInterface $cache, $persistent = false)
 {
     $identifier = $cache->getIdentifier();
     if (isset($this->caches[$identifier])) {
         throw new DuplicateIdentifierException('A cache with identifier "' . $identifier . '" has already been registered.', 1203698223);
     }
     $this->caches[$identifier] = $cache;
     if ($persistent === true) {
         $this->persistentCaches[$identifier] = $cache;
     }
 }
 /**
  * Sets a reference to the cache frontend which uses this backend
  *
  * @param FrontendInterface $cache The frontend for this backend
  * @return void
  * @api
  */
 public function setCache(FrontendInterface $cache)
 {
     $this->cache = $cache;
     $this->cacheIdentifier = $this->cache->getIdentifier();
 }
 /**
  * Deletes a cache entry.
  *
  * @param string $id The cache id.
  * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
  */
 public function delete($id)
 {
     return $this->cache->remove($this->convertCacheIdentifier($id));
 }
 /**
  * Returns the data of the current cache entry pointed to by the cache entry
  * iterator.
  *
  * @return mixed
  * @api
  */
 public function current()
 {
     return $this->frontend->get($this->backend->key());
 }