/** * Creates a cache for testing * * @param string $name * @return VariableFrontend */ protected function createCache($name) { $backend = new FileBackend(new EnvironmentConfiguration('Session Testing', 'vfs://Foo/', PHP_MAXPATHLEN)); $cache = new VariableFrontend($name, $backend); $cache->initializeObject(); $backend->setCache($cache); $cache->flush(); return $cache; }
/** * Constructs this backend * * @param ApplicationContext $context Flow's application context * @param array $options Configuration options - depends on the actual backend */ public function __construct(ApplicationContext $context, array $options = []) { $this->context = $context; $environmentConfiguration = $this->createEnvironmentConfiguration($context); parent::__construct($environmentConfiguration, $options); }
/** * @test */ public function backendAllowsForIteratingOverEntries() { $mockEnvironmentConfiguration = $this->createEnvironmentConfigurationMock([__DIR__ . '~Testing', 'vfs://Foo/', 255]); $backend = new FileBackend($mockEnvironmentConfiguration, []); $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 = []; 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); }