/**
  * @dataProvider provideTestDirs
  */
 public function testAddDir($dirname, $expected_result, $manipulate, $zipContentsOnly = false)
 {
     # Create new archive
     $archive = '/tmp/archive.zip';
     $zip = new ZipArchiveEx();
     $zip->open($archive, ZIPARCHIVE::OVERWRITE);
     # Try to add directory:
     if ($zipContentsOnly) {
         $result = $zip->addDirContents($dirname);
     } else {
         $result = $zip->addDir($dirname);
     }
     $this->assertEquals($expected_result, $result);
     # Close archive:
     $zip->close();
     # If directory was added successfully
     if ($result) {
         # Remove extracted testdirectory from
         # former testruns:
         $extractionDir = self::$tmpDir . '/' . basename($dirname);
         FileSystemManager::rrmdir($extractionDir);
         # Extract directory
         $output = array();
         # -u Option forces update of already existing files,
         # importang for testing on travis-ci.org!
         $extractTo = $zipContentsOnly ? $extractionDir : self::$tmpDir;
         exec('unzip -u ' . $archive . ' -d ' . $extractTo, $output, $result);
         $this->assertEquals(0, $result);
         # 0 = successfull
         # $manipulate holds the file to manipulate,
         # so the following assertion fails.
         if ($manipulate) {
             file_put_contents($extractionDir . '/' . $manipulate, 'Lorem ipsum dolor sit amet.');
             $expected_result = 1;
         } else {
             $expected_result = 0;
         }
         # Compare extracted directory and original one
         exec('diff -arq ' . $dirname . ' ' . $extractionDir, $output, $result);
         LogMore::debug('Output of diff-command: %s', implode(PHP_EOL, $output));
         LogMore::debug('Expecting %d, got: %d', $expected_result, $result);
         $this->assertEquals($expected_result, $result);
     }
 }
 /**
  * Helper to create a ZIP out of a data file and the configuration file
  */
 protected function DoZip($aFiles, $sZipArchiveFile)
 {
     foreach ($aFiles as $aFile) {
         $sFile = $aFile['source'];
         if (!is_file($sFile) && !is_dir($sFile)) {
             throw new BackupException("File '{$sFile}' does not exist or could not be read");
         }
     }
     // Make sure the target path exists
     $sZipDir = dirname($sZipArchiveFile);
     SetupUtils::builddir($sZipDir);
     $oZip = new ZipArchiveEx();
     $res = $oZip->open($sZipArchiveFile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
     if ($res === TRUE) {
         foreach ($aFiles as $aFile) {
             if (is_dir($aFile['source'])) {
                 $oZip->addDir($aFile['source'], $aFile['dest']);
             } else {
                 $oZip->addFile($aFile['source'], $aFile['dest']);
             }
         }
         if ($oZip->close()) {
             $this->LogInfo("Archive: {$sZipArchiveFile} created");
         } else {
             $this->LogError("Failed to save zip archive: {$sZipArchiveFile}");
             throw new BackupException("Failed to save zip archive: {$sZipArchiveFile}");
         }
     } else {
         $this->LogError("Failed to create zip archive: {$sZipArchiveFile}.");
         throw new BackupException("Failed to create zip archive: {$sZipArchiveFile}.");
     }
 }