public function testZip() { if (class_exists('ZipArchive', false)) { $a = new Archive('test.zip'); unset($a); $a = new Archive('C:\\Projects\\..\\test.zip'); unset($a); $a = new Archive(__DIR__ . '/../tmp/test.zip'); $a->addFiles(array(__DIR__ . '/../tmp/access.txt', __DIR__ . '/../tmp/test.jpg', __DIR__ . '/TarTest.php', __DIR__ . '/../../../../../public/examples/assets')); $this->assertGreaterThan(1, count($a->adapter()->getDirs())); unset($a); $a = new Archive(__DIR__ . '/../tmp/test.zip'); $a->addFiles(__DIR__ . '/./'); unset($a); $a = new Archive(__DIR__ . '/../tmp/test.zip'); $a->addFiles(__DIR__ . '/../tmp'); $this->assertFileExists(__DIR__ . '/../tmp/test.zip'); $this->assertGreaterThan(60000, $a->getSize()); chmod(__DIR__ . '/../tmp/test.zip', 0777); unset($a); mkdir(__DIR__ . '/../tmp/test'); mkdir(__DIR__ . '/../tmp/test/test'); touch(__DIR__ . '/../tmp/empty'); touch(__DIR__ . '/../tmp/test/empty'); touch(__DIR__ . '/../tmp/test/test/empty'); chmod(__DIR__ . '/../tmp/test', 0777); chmod(__DIR__ . '/../tmp/test/test', 0777); chmod(__DIR__ . '/../tmp/empty', 0777); chmod(__DIR__ . '/../tmp/test/empty', 0777); chmod(__DIR__ . '/../tmp/test/test/empty', 0777); $a = new Archive(__DIR__ . '/../tmp/test.zip'); $a->addFiles(__DIR__ . '/../tmp/empty'); $a->addFiles(__DIR__ . '/../tmp/test'); $files = $a->listFiles(); $files = $a->listFiles(true); $this->assertTrue(is_array($files)); unset($a); if (file_exists(__DIR__ . '/../tmp/test.zip')) { unlink(__DIR__ . '/../tmp/test.zip'); } if (file_exists(__DIR__ . '/../tmp/empty')) { unlink(__DIR__ . '/../tmp/empty'); } $dir = new Dir(__DIR__ . '/../tmp/test'); $dir->emptyDir(); rmdir(__DIR__ . '/../tmp/test'); } }
<?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 testTbz2() { $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'); $a->compress('bz'); $this->assertFileExists(__DIR__ . '/../tmp/test.tar.bz2'); $this->assertGreaterThan(60000, $a->getSize()); if (file_exists(__DIR__ . '/../tmp/test.tar.bz2')) { unlink(__DIR__ . '/../tmp/test.tar.bz2'); } unset($a); $a = new Archive(__DIR__ . '/../tmp/test.tar'); $a->addFiles(__DIR__ . '/../tmp'); $a->compress('tbz2'); $this->assertFileExists(__DIR__ . '/../tmp/test.tbz2'); $this->assertGreaterThan(60000, $a->getSize()); if (file_exists(__DIR__ . '/../tmp/test.tbz2')) { unlink(__DIR__ . '/../tmp/test.tbz2'); } unset($a); $a = new Archive(__DIR__ . '/../tmp/test.tar'); $a->addFiles(__DIR__ . '/../tmp'); $a->compress('tbz'); $this->assertFileExists(__DIR__ . '/../tmp/test.tbz'); $this->assertGreaterThan(60000, $a->getSize()); if (file_exists(__DIR__ . '/../tmp/test.tbz')) { unlink(__DIR__ . '/../tmp/test.tbz'); } } }