Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test case for inconsistent PHPZipMerge merged zip
// Put this file in a subdirectory inside the PHPZipMerge repository, then execute it.
ini_set('open_basedir', dirname(__DIR__)); // Security: restrict file access to parent directory.
require __DIR__.'/../vendor/autoload.php';
$srcName = '';
$src = __DIR__.'/'.$srcName;
if(file_exists($src)) unlink($src);
$mergedName = '';
$merged = __DIR__.'/'.$mergedName;
if(file_exists($merged)) unlink($merged);
// Creating the source
$zip = new \ZipArchive();
$res = $zip->open($src, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
if($res !== true) {
// List of error codes at:
throw new \Exception("Opening $srcName error code: $res");
$zip->addFromString('hello.txt', 'Hello test !');
$res = $zip->close();
if($res !== true) {
throw new \Exception("Zip could not be saved correctly: $src");
// Merging into a new file
$zipMerge = new \ZipMerge\Zip\File\ZipMergeToFile($merged);
// Checking consistency of
$zipCheck = new \ZipArchive();
$res = $zipCheck->open($merged, \ZipArchive::CHECKCONS);
if ($res !== true) {
// List of error codes at:
if($res === 21) throw new \Exception("Checking $mergedName error code: $res (ZipArchive::ER_INCONS => 'Zip archive inconsistent')");
else throw new \Exception("Checking $mergedName error code: $res");
// If we reach here, no error happened :)
echo "Test success, no error encountered." . PHP_EOL;

This comment has been minimized.

Copy link
Owner Author

commented Jul 20, 2016

Test case for: Grandt/PHPZipMerge#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.