1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-07-18 06:31:13 +02:00

Merge tag '3.1.10' into develop

Tagging hotfix 3.1.10 3.1.10
This commit is contained in:
Ne-Lexa
2019-03-13 15:16:08 +03:00
5 changed files with 32 additions and 22 deletions

View File

@@ -15,7 +15,7 @@ class ZipAlignTest extends ZipTestCase
*/ */
public function testApkAlignedAndSetZipAlignAndReSave() public function testApkAlignedAndSetZipAlignAndReSave()
{ {
$filename = __DIR__ . '/resources/test.apk'; $filename = __DIR__ . '/resources/apk.zip';
$this->assertCorrectZipArchive($filename); $this->assertCorrectZipArchive($filename);
$result = $this->assertVerifyZipAlign($filename); $result = $this->assertVerifyZipAlign($filename);

View File

@@ -22,7 +22,7 @@ class ZipEventTest extends ZipTestCase
public function testBeforeSave() public function testBeforeSave()
{ {
$zipFile = new ZipFileExtended(); $zipFile = new ZipFileExtended();
$zipFile->openFile(__DIR__ . '/resources/test.apk'); $zipFile->openFile(__DIR__ . '/resources/apk.zip');
$this->assertTrue(isset($zipFile['META-INF/MANIFEST.MF'])); $this->assertTrue(isset($zipFile['META-INF/MANIFEST.MF']));
$this->assertTrue(isset($zipFile['META-INF/CERT.SF'])); $this->assertTrue(isset($zipFile['META-INF/CERT.SF']));
$this->assertTrue(isset($zipFile['META-INF/CERT.RSA'])); $this->assertTrue(isset($zipFile['META-INF/CERT.RSA']));

View File

@@ -10,7 +10,6 @@ use PhpZip\Util\FilesUtil;
*/ */
class ZipTestCase extends \PHPUnit_Framework_TestCase class ZipTestCase extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var string * @var string
*/ */
@@ -27,12 +26,10 @@ class ZipTestCase extends \PHPUnit_Framework_TestCase
{ {
parent::setUp(); parent::setUp();
$id = uniqid('phpzip'); $id = uniqid('phpzip', true);
$tempDir = sys_get_temp_dir() . '/phpunit-phpzip'; $tempDir = sys_get_temp_dir() . '/phpunit-phpzip';
if (!is_dir($tempDir)) { if (!is_dir($tempDir) && !mkdir($tempDir, 0755, true) && !is_dir($tempDir)) {
if (!mkdir($tempDir, 0755, true)) { throw new \RuntimeException('Dir ' . $tempDir . " can't created");
throw new \RuntimeException("Dir " . $tempDir . " can't created");
}
} }
$this->outputFilename = $tempDir . '/' . $id . '.zip'; $this->outputFilename = $tempDir . '/' . $id . '.zip';
$this->outputDirname = $tempDir . '/' . $id; $this->outputDirname = $tempDir . '/' . $id;
@@ -61,23 +58,23 @@ class ZipTestCase extends \PHPUnit_Framework_TestCase
*/ */
public static function assertCorrectZipArchive($filename, $password = null) public static function assertCorrectZipArchive($filename, $password = null)
{ {
if (DIRECTORY_SEPARATOR !== '\\' && `which unzip`) { if (self::existsProgram('unzip')) {
$command = "unzip"; $command = 'unzip';
if ($password !== null) { if ($password !== null) {
$command .= " -P " . escapeshellarg($password); $command .= ' -P ' . escapeshellarg($password);
} }
$command .= " -t " . escapeshellarg($filename); $command .= ' -t ' . escapeshellarg($filename);
exec($command, $output, $returnCode); exec($command, $output, $returnCode);
$output = implode(PHP_EOL, $output); $output = implode(PHP_EOL, $output);
if ($password !== null && $returnCode === 81) { if ($password !== null && $returnCode === 81) {
if (`which 7z`) { if (self::existsProgram('7z')) {
// WinZip 99-character limit // WinZip 99-character limit
// @see https://sourceforge.net/p/p7zip/discussion/383044/thread/c859a2f0/ // @see https://sourceforge.net/p/p7zip/discussion/383044/thread/c859a2f0/
$password = substr($password, 0, 99); $password = substr($password, 0, 99);
$command = "7z t -p" . escapeshellarg($password) . " " . escapeshellarg($filename); $command = '7z t -p' . escapeshellarg($password) . ' ' . escapeshellarg($filename);
exec($command, $output, $returnCode); exec($command, $output, $returnCode);
/** /**
* @var array $output * @var array $output
@@ -100,6 +97,19 @@ class ZipTestCase extends \PHPUnit_Framework_TestCase
} }
} }
/**
* @param string $program
* @return bool
*/
private static function existsProgram($program){
if (DIRECTORY_SEPARATOR !== '\\') {
exec('which ' . escapeshellarg($program), $output, $returnCode);
return $returnCode === 0;
}
// false for Windows
return false;
}
/** /**
* Assert correct empty zip archive. * Assert correct empty zip archive.
* *
@@ -107,15 +117,15 @@ class ZipTestCase extends \PHPUnit_Framework_TestCase
*/ */
public static function assertCorrectEmptyZip($filename) public static function assertCorrectEmptyZip($filename)
{ {
if (DIRECTORY_SEPARATOR !== '\\' && `which zipinfo`) { if (self::existsProgram('zipinfo')) {
exec("zipinfo " . escapeshellarg($filename), $output, $returnCode); exec('zipinfo ' . escapeshellarg($filename), $output, $returnCode);
$output = implode(PHP_EOL, $output); $output = implode(PHP_EOL, $output);
self::assertContains('Empty zipfile', $output); self::assertContains('Empty zipfile', $output);
} }
$actualEmptyZipData = pack('VVVVVv', EndOfCentralDirectory::END_OF_CENTRAL_DIRECTORY_RECORD_SIG, 0, 0, 0, 0, 0); $actualEmptyZipData = pack('VVVVVv', EndOfCentralDirectory::END_OF_CENTRAL_DIRECTORY_RECORD_SIG, 0, 0, 0, 0, 0);
self::assertEquals(file_get_contents($filename), $actualEmptyZipData); self::assertStringEqualsFile($filename, $actualEmptyZipData);
} }
/** /**
@@ -125,15 +135,15 @@ class ZipTestCase extends \PHPUnit_Framework_TestCase
*/ */
public static function assertVerifyZipAlign($filename, $showErrors = false) public static function assertVerifyZipAlign($filename, $showErrors = false)
{ {
if (DIRECTORY_SEPARATOR !== '\\' && `which zipalign`) { if (self::existsProgram('zipalign')) {
exec("zipalign -c -v 4 " . escapeshellarg($filename), $output, $returnCode); exec('zipalign -c -v 4 ' . escapeshellarg($filename), $output, $returnCode);
if ($showErrors && $returnCode !== 0) { if ($showErrors && $returnCode !== 0) {
fwrite(STDERR, implode(PHP_EOL, $output)); fwrite(STDERR, implode(PHP_EOL, $output));
} }
return $returnCode === 0; return $returnCode === 0;
} else {
fwrite(STDERR, 'Can not find program "zipalign" for test' . PHP_EOL);
return null;
} }
fwrite(STDERR, 'Can not find program "zipalign" for test' . PHP_EOL);
return null;
} }
} }

Binary file not shown.

Binary file not shown.