示例#1
0
 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'));
 }
示例#2
0
 /**
  * @param bool|null $recursive
  */
 public function delete($recursive = null)
 {
     if ($recursive) {
         $this->_filesystem->deleteByPrefix($this->getPath());
     }
     $this->_filesystem->delete($this->getPath());
     $cache = CM_Cache_Storage_Runtime::getInstance();
     $cache->delete($this->_getCacheKeyContent());
 }
示例#3
0
 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');
 }