Ejemplo n.º 1
0
 /**
  * @test
  */
 public function backendAllowsForIteratingOverEntries()
 {
     $mockEnvironment = $this->getMock('TYPO3\\Flow\\Utility\\Environment', array(), array(), '', FALSE);
     $mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(255));
     $mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $mockCacheManager = $this->getMock('TYPO3\\Flow\\Cache\\CacheManager', array(), array(), '', FALSE);
     $mockCacheManager->expects($this->any())->method('isCachePersistent')->will($this->returnValue(FALSE));
     $backend = new FileBackend(new ApplicationContext('Testing'));
     $backend->injectCacheManager($mockCacheManager);
     $backend->injectEnvironment($mockEnvironment);
     $cache = new VariableFrontend('UnitTestCache', $backend);
     $backend->setCache($cache);
     for ($i = 0; $i < 100; $i++) {
         $entryIdentifier = sprintf('entry-%s', $i);
         $data = 'some data ' . $i;
         $cache->set($entryIdentifier, $data);
     }
     $entries = array();
     foreach ($cache->getIterator() as $entryIdentifier => $data) {
         $entries[$entryIdentifier] = $data;
     }
     natsort($entries);
     $i = 0;
     foreach ($entries as $entryIdentifier => $data) {
         $this->assertEquals(sprintf('entry-%s', $i), $entryIdentifier);
         $this->assertEquals('some data ' . $i, $data);
         $i++;
     }
     $this->assertEquals(100, $i);
 }
 /**
  * Creates a cache for testing
  *
  * @param string $name
  * @return VariableFrontend
  */
 protected function createCache($name)
 {
     $mockEnvironment = $this->getMock(\TYPO3\Flow\Utility\Environment::class, array(), array(), '', FALSE);
     $mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(255));
     $mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $mockCacheManager = $this->getMock(\TYPO3\Flow\Cache\CacheManager::class, array(), array(), '', FALSE);
     $mockCacheManager->expects($this->any())->method('isCachePersistent')->will($this->returnValue(FALSE));
     $backend = new FileBackend(new ApplicationContext('Testing'));
     $backend->injectCacheManager($mockCacheManager);
     $backend->injectEnvironment($mockEnvironment);
     $cache = new VariableFrontend($name, $backend);
     $cache->initializeObject();
     $cache->flush();
     return $cache;
 }