/** * @param string $destinationFile * @param string $extensionRequired * @dataProvider tarProvider */ public function testExtract($destinationFile, $extensionRequired) { if ($extensionRequired && !extension_loaded($extensionRequired)) { $this->markTestSkipped("The extension '{$extensionRequired}' is not enabled."); } $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile); $this->assertFileExists($this->packed); $this->assertEquals($this->destinationDir . $destinationFile, $this->packed); $filename = pathinfo($this->sourceFilePath, PATHINFO_BASENAME); $this->unpacked = $this->archive->extract($filename, $this->packed, $this->destinationDir); $this->assertFileExists($this->unpacked); $this->assertStringStartsWith($this->destinationDir, $this->unpacked); }
<?php error_reporting(-1); // для демонстрации копирования максимального файла без полного занесения в память ini_set('memory_limit', '1M'); require_once __DIR__ . DIRECTORY_SEPARATOR . 'archive.php'; $dirIn = __DIR__ . DIRECTORY_SEPARATOR . 'in'; $dirOut = __DIR__ . DIRECTORY_SEPARATOR . 'out'; $fileArchive = __DIR__ . DIRECTORY_SEPARATOR . 'archive'; ?> <!DOCTYPE html> <html lang="ru"> <head><meta charset="utf-8"></head> <body> <?php if (Archive::pack($dirIn, $fileArchive)) { ?> Создан архив <b><?php echo $fileArchive; ?> <br/></b> <?php } ?> <?php if (Archive::unpack($dirOut, $fileArchive)) { ?> И успешно распакован в директорию <b><?php echo $dirOut; ?> </b>