public function testBzip2WithTarFile() { $tar = false; $includePath = explode(PATH_SEPARATOR, get_include_path()); foreach ($includePath as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) { $tar = true; } } if ($tar && function_exists('bzopen')) { $a = new Archive(__DIR__ . '/../tmp/test.tar'); $a->addFiles(__DIR__ . '/../tmp'); $compressed = Bzip2::compress(__DIR__ . '/../tmp/test.tar'); copy($compressed, __DIR__ . '/../tmp/test.tbz2'); copy($compressed, __DIR__ . '/../tmp/test.tbz'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); $this->fileExists(__DIR__ . '/../tmp/test.tar.bz2'); $this->fileExists(__DIR__ . '/../tmp/test.tbz2'); $this->fileExists(__DIR__ . '/../tmp/test.tbz'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } // Test *.tar.bz2 $decompressed = Bzip2::decompress(__DIR__ . '/../tmp/test.tar.bz2'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } if (file_exists(__DIR__ . '/../tmp/test.tar.bz2')) { unlink(__DIR__ . '/../tmp/test.tar.bz2'); } // Test *.tbz2 $decompressed = Bzip2::decompress(__DIR__ . '/../tmp/test.tbz2'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } if (file_exists(__DIR__ . '/../tmp/test.tbz2')) { unlink(__DIR__ . '/../tmp/test.tbz2'); } // Test *.tbz $decompressed = Bzip2::decompress(__DIR__ . '/../tmp/test.tbz'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } if (file_exists(__DIR__ . '/../tmp/test.tbz')) { unlink(__DIR__ . '/../tmp/test.tbz'); } } }
public function testZipExtract() { if (class_exists('ZipArchive', false)) { $a = new Archive(__DIR__ . '/../tmp/test.zip'); $a->addFiles(__DIR__ . '/../tmp'); mkdir(__DIR__ . '/../tmp/test'); chmod(__DIR__ . '/../tmp/test', 0777); chmod(__DIR__ . '/../tmp/test.zip', 0777); $a->extract(__DIR__ . '/../tmp/test'); unset($a); $dir = new Dir(__DIR__ . '/../tmp/test'); $this->assertGreaterThan(0, count($dir->getFiles())); $dir->emptyDir(); rmdir(__DIR__ . '/../tmp/test'); if (file_exists(__DIR__ . '/../tmp/test.zip')) { unlink(__DIR__ . '/../tmp/test.zip'); } } }
<?php require_once '../../bootstrap.php'; use Pop\Archive\Archive; try { // Create a new ZIP archive and add some files to it // (Make sure the '../tmp' folder is writable) $archive = new Archive('../tmp/test.zip'); $archive->addFiles('../assets'); // Display the new archive file size echo $archive->getBasename() . ': compressed file size => ' . $archive->getSize() . '<br /> ' . PHP_EOL; echo 'Done.'; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }
public function testNoCompress() { $tar = false; $includePath = explode(PATH_SEPARATOR, get_include_path()); foreach ($includePath as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) { $tar = true; } } if ($tar) { $a = new Archive(__DIR__ . '/../tmp/test.tar'); $a->addFiles(__DIR__ . '/../tmp'); $a->compress('.noext'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } } }