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')); }
/** * Construct shell command for creating backup archive. * * @param string $backupFilePath * @return string */ protected function buildShellCommand($backupFilePath) { $excludedElements = ''; foreach ($this->backupInfo->getBlacklist() as $excludedElement) { $elementPath = $excludedElement; $fullPath = $this->backupInfo->getArchivedDirectory() . '/' . $elementPath; $excludedElements .= is_dir($fullPath) ? $elementPath . '\\* ' : $elementPath . ' '; } $changeDirectoryCommand = sprintf("cd %s", $this->backupInfo->getArchivedDirectory()); $zipCommand = sprintf("zip -r %s . -x %s", $backupFilePath, $excludedElements); return $changeDirectoryCommand . ' && ' . $zipCommand; }