public function testRestoreByCopyingOldVersion() { $this->_filesystem->write('bar', 'mega1'); sleep(1); $this->_filesystem->write('bar', 'mega2'); sleep(1); $this->_filesystem->delete('bar'); sleep(1); $this->_filesystem->write('bar', 'mega3'); sleep(1); $this->_filesystem->write('bar', 'mega4'); $versionList = $this->_restore->getVersions('bar'); /** @var DateTime[] $lastModifiedList */ $lastModifiedList = Functional\map($versionList, function (CMService_AwsS3Versioning_Response_Version $version) { return $version->getLastModified(); }); $this->_restore->restoreByCopyingOldVersion('bar', $lastModifiedList[0]->add(new DateInterval('PT1S'))); $this->assertCount(5, $this->_restore->getVersions('bar')); $this->assertSame('mega4', $this->_filesystem->read('bar')); $this->_restore->restoreByCopyingOldVersion('bar', $lastModifiedList[1]); $this->assertCount(6, $this->_restore->getVersions('bar')); $this->assertSame('mega3', $this->_filesystem->read('bar')); $this->_restore->restoreByCopyingOldVersion('bar', $lastModifiedList[2]); $this->assertCount(7, $this->_restore->getVersions('bar')); $this->assertSame(false, $this->_filesystem->exists('bar')); $this->_restore->restoreByCopyingOldVersion('bar', $lastModifiedList[4]); $this->assertCount(8, $this->_restore->getVersions('bar')); $this->assertSame('mega1', $this->_filesystem->read('bar')); $this->_restore->restoreByCopyingOldVersion('bar', $lastModifiedList[4]->sub(new DateInterval('PT1S'))); $this->assertCount(9, $this->_restore->getVersions('bar')); $this->assertSame(false, $this->_filesystem->exists('bar')); }
/** * @return string */ public function read() { $cache = CM_Cache_Storage_Runtime::getInstance(); if (false === ($content = $cache->get($this->_getCacheKeyContent()))) { $content = $this->_filesystem->read($this->getPath()); $cache->set($this->_getCacheKeyContent(), $content, 1); } return $content; }
public function testSecondary() { $dirTmp = CM_Bootloader::getInstance()->getDirTmp(); $filesystem = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local($dirTmp)); $filesystemSecondary = $this->getMockBuilder('CM_File_Filesystem')->disableOriginalConstructor()->setMethods(array('write', 'read', 'rename', 'copy', 'append', 'delete', 'ensureDirectory', 'deleteByPrefix'))->getMock(); $filesystemSecondary->expects($this->once())->method('write')->with('/foo', 'hello'); $filesystemSecondary->expects($this->never())->method('read'); $filesystemSecondary->expects($this->once())->method('append')->with('/foo', 'world'); $filesystemSecondary->expects($this->once())->method('rename')->with('/foo', '/bar'); $filesystemSecondary->expects($this->once())->method('copy')->with('/bar', '/foo'); $filesystemSecondary->expects($this->once())->method('delete')->with('/bar'); $filesystemSecondary->expects($this->once())->method('ensureDirectory')->with('/my-dir'); $filesystemSecondary->expects($this->once())->method('deleteByPrefix')->with('/my-dir'); /** @var CM_File_Filesystem $filesystemSecondary */ $filesystem->addSecondary($filesystemSecondary); $filesystem->write('/foo', 'hello'); $filesystem->read('/foo'); $filesystem->append('/foo', 'world'); $filesystem->rename('/foo', '/bar'); $filesystem->copy('/bar', '/foo'); $filesystem->delete('/bar'); $filesystem->ensureDirectory('/my-dir'); $filesystem->deleteByPrefix('/my-dir'); }