public function testAutoRollback() { // Setup $this->autoRollbackHelper(); $this->backupFile->buildFromDirectory($this->archivedDir); $this->backupFile->addEmptyDir("testDirectory"); $this->backupFile->compress(\Phar::GZ, '.tgz'); $newFile = $this->backupPath . '/' . uniqid() . '_code.tgz'; copy($this->backupFileName, $newFile); if (file_exists($this->backupFileName)) { unset($this->backupFile); unlink($this->backupFileName); } $gtzFile = str_replace('tar', 'tgz', $this->backupFileName); if (file_exists($gtzFile)) { unlink($gtzFile); } $this->backupFileName = $newFile; // Change the contents of a.txt $this->autoRollbackHelper(1); $this->assertEquals('foo changed', file_get_contents($this->archivedDir . 'a.txt')); $this->backupInfo->expects($this->once())->method('getBlacklist')->willReturn(['excluded']); // Rollback process $this->rollBack->execute($this->backupFileName); // Assert that the contents of a.txt has been restored properly $this->assertEquals('foo', file_get_contents($this->archivedDir . 'a.txt')); }
/** * {@inheritdoc} */ public function execute() { $rollBack = new Rollback(); $backupFileName = !isset($this->params[self::BACKUP_FILE_NAME]) ? null : $this->params[self::BACKUP_FILE_NAME]; $rollBack->execute($backupFileName); return $this; }
/** * {@inheritdoc} */ public function execute() { if (!isset($this->params[self::BACKUP_FILE_NAME])) { throw new \RuntimeException('Missing required parameter: ' . self::BACKUP_FILE_NAME); } $rollBack = new Rollback(); $this->maintenanceMode->set(true); $rollBack->execute($this->params[self::BACKUP_FILE_NAME]); $this->maintenanceMode->set(false); return $this; }
public function testAutoRollback() { // Setup $this->autoRollbackHelper(); $backupInfo = $this->getMockBuilder('Magento\\Update\\Backup\\BackupInfo')->disableOriginalConstructor()->setMethods(['generateBackupFilename', 'getBackupPath', 'getBlacklist', 'getArchivedDirectory'])->getMock(); $backupInfo->expects($this->any())->method('generateBackupFilename')->willReturn($this->backupFileName); $backupInfo->expects($this->any())->method('getBackupPath')->willReturn($this->backupPath); $backupInfo->expects($this->any())->method('getArchivedDirectory')->willReturn($this->archivedDir); $backupInfo->expects($this->any())->method('getBlacklist')->willReturn([$this->excludedDir]); $statusMock = $this->getMockBuilder('Magento\\Update\\Status')->disableOriginalConstructor()->getMock(); $backup = new \Magento\Update\Backup($backupInfo, $statusMock); $backupFilePath = $this->backupPath . $this->backupFileName; $statusMock->expects($this->at(0))->method('add')->with(sprintf('Creating backup archive "%s" ...', $backupFilePath)); $statusMock->expects($this->at(1))->method('add')->with(sprintf('Backup archive "%s" has been created.', $backupFilePath)); $result = $backup->execute(); $this->assertInstanceOf('Magento\\Update\\Backup', $result); // Change the contents of a.txt $this->autoRollbackHelper(1); $this->assertEquals('foo changed', file_get_contents($this->archivedDir . 'a.txt')); // Rollback process $this->rollBack->execute(); // Assert that the contents of a.txt has been restored properly $this->assertEquals('foo', file_get_contents($this->archivedDir . 'a.txt')); }