mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-08-08 00:16:28 +02:00
solving problems with lack of memory, the new ZipReader and ZipWriter class, adds .phpstorm.meta.php
#13 #16 #27 #31 #41
This commit is contained in:
216
tests/Internal/DummyFileSystemStream.php
Normal file
216
tests/Internal/DummyFileSystemStream.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests\Internal;
|
||||
|
||||
/**
|
||||
* Try to load using dummy stream.
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper
|
||||
*/
|
||||
class DummyFileSystemStream
|
||||
{
|
||||
/** @var resource */
|
||||
private $fp;
|
||||
|
||||
/**
|
||||
* Opens file or URL.
|
||||
*
|
||||
* This method is called immediately after the wrapper is
|
||||
* initialized (f.e. by {@see fopen()} and {@see file_get_contents()}).
|
||||
*
|
||||
* @param string $path specifies the URL that was passed to
|
||||
* the original function
|
||||
* @param string $mode the mode used to open the file, as detailed
|
||||
* for {@see fopen()}
|
||||
* @param int $options Holds additional flags set by the streams
|
||||
* API. It can hold one or more of the
|
||||
* following values OR'd together.
|
||||
* @param string $opened_path if the path is opened successfully, and
|
||||
* STREAM_USE_PATH is set in options,
|
||||
* opened_path should be set to the
|
||||
* full path of the file/resource that
|
||||
* was actually opened
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-open
|
||||
*
|
||||
* @noinspection PhpUsageOfSilenceOperatorInspection
|
||||
*/
|
||||
public function stream_open($path, $mode, $options, &$opened_path)
|
||||
{
|
||||
$parsedUrl = parse_url($path);
|
||||
$uri = str_replace('//', '/', $parsedUrl['path']);
|
||||
$this->fp = @fopen($uri, $mode);
|
||||
|
||||
return $this->fp !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from stream.
|
||||
*
|
||||
* This method is called in response to {@see fread()} and {@see fgets()}.
|
||||
*
|
||||
* Note: Remember to update the read/write position of the stream
|
||||
* (by the number of bytes that were successfully read).
|
||||
*
|
||||
* @param int $count how many bytes of data from the current
|
||||
* position should be returned
|
||||
*
|
||||
* @return false|string If there are less than count bytes available,
|
||||
* return as many as are available. If no more data
|
||||
* is available, return either FALSE or
|
||||
* an empty string.
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-read
|
||||
*/
|
||||
public function stream_read($count)
|
||||
{
|
||||
return fread($this->fp, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks to specific location in a stream.
|
||||
*
|
||||
* This method is called in response to {@see fseek()}.
|
||||
* The read/write position of the stream should be updated according
|
||||
* to the offset and whence.
|
||||
*
|
||||
* @param int $offset the stream offset to seek to
|
||||
* @param int $whence Possible values:
|
||||
* {@see \SEEK_SET} - Set position equal to offset bytes.
|
||||
* {@see \SEEK_CUR} - Set position to current location plus offset.
|
||||
* {@see \SEEK_END} - Set position to end-of-file plus offset.
|
||||
*
|
||||
* @return bool return TRUE if the position was updated, FALSE otherwise
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-seek
|
||||
*/
|
||||
public function stream_seek($offset, $whence = \SEEK_SET)
|
||||
{
|
||||
return fseek($this->fp, $offset, $whence) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current position of a stream.
|
||||
*
|
||||
* This method is called in response to {@see fseek()} to determine
|
||||
* the current position.
|
||||
*
|
||||
* @return int should return the current position of the stream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-tell
|
||||
*/
|
||||
public function stream_tell()
|
||||
{
|
||||
$pos = ftell($this->fp);
|
||||
|
||||
if ($pos === false) {
|
||||
throw new \RuntimeException('Cannot get stream position.');
|
||||
}
|
||||
|
||||
return $pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for end-of-file on a file pointer.
|
||||
*
|
||||
* This method is called in response to {@see feof()}.
|
||||
*
|
||||
* @return bool should return TRUE if the read/write position is at
|
||||
* the end of the stream and if no more data is available
|
||||
* to be read, or FALSE otherwise
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-eof
|
||||
*/
|
||||
public function stream_eof()
|
||||
{
|
||||
return feof($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve information about a file resource.
|
||||
*
|
||||
* This method is called in response to {@see fstat()}.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-stat
|
||||
* @see https://www.php.net/stat
|
||||
* @see https://www.php.net/fstat
|
||||
*/
|
||||
public function stream_stat()
|
||||
{
|
||||
return fstat($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the output.
|
||||
*
|
||||
* This method is called in response to {@see fflush()} and when the
|
||||
* stream is being closed while any unflushed data has been written to
|
||||
* it before.
|
||||
* If you have cached data in your stream but not yet stored it into
|
||||
* the underlying storage, you should do so now.
|
||||
*
|
||||
* @return bool should return TRUE if the cached data was successfully
|
||||
* stored (or if there was no data to store), or FALSE
|
||||
* if the data could not be stored
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-flush
|
||||
*/
|
||||
public function stream_flush()
|
||||
{
|
||||
return fflush($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate stream.
|
||||
*
|
||||
* Will respond to truncation, e.g., through {@see ftruncate()}.
|
||||
*
|
||||
* @param int $new_size the new size
|
||||
*
|
||||
* @return bool returns TRUE on success or FALSE on failure
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-truncate
|
||||
*/
|
||||
public function stream_truncate($new_size)
|
||||
{
|
||||
return ftruncate($this->fp, (int) $new_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to stream.
|
||||
*
|
||||
* This method is called in response to {@see fwrite().}
|
||||
*
|
||||
* Note: Remember to update the current position of the stream by
|
||||
* number of bytes that were successfully written.
|
||||
*
|
||||
* @param string $data should be stored into the underlying stream
|
||||
*
|
||||
* @return int should return the number of bytes that were successfully stored, or 0 if none could be stored
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-write
|
||||
*/
|
||||
public function stream_write($data)
|
||||
{
|
||||
$bytes = fwrite($this->fp, $data);
|
||||
|
||||
return $bytes === false ? 0 : $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a resource.
|
||||
*
|
||||
* This method is called in response to {@see fclose()}.
|
||||
* All resources that were locked, or allocated, by the wrapper should be released.
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-close
|
||||
*/
|
||||
public function stream_close()
|
||||
{
|
||||
fclose($this->fp);
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Internal;
|
||||
namespace PhpZip\Tests\Internal;
|
||||
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
@@ -12,7 +12,6 @@ class ZipFileExtended extends ZipFile
|
||||
protected function onBeforeSave()
|
||||
{
|
||||
parent::onBeforeSave();
|
||||
$this->setZipAlign(4);
|
||||
$this->deleteFromRegex('~^META\-INF/~i');
|
||||
}
|
||||
}
|
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Tests\Internal\DummyFileSystemStream;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -11,6 +13,8 @@ use PhpZip\Exception\ZipException;
|
||||
*/
|
||||
class Issue24Test extends ZipTestCase
|
||||
{
|
||||
const PROTO_DUMMYFS = 'dummyfs';
|
||||
|
||||
/**
|
||||
* This method is called before the first test of this test class is run.
|
||||
*
|
||||
@@ -18,7 +22,7 @@ class Issue24Test extends ZipTestCase
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
stream_wrapper_register('dummyfs', Internal\DummyFileSystemStream::class);
|
||||
stream_wrapper_register(self::PROTO_DUMMYFS, DummyFileSystemStream::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +45,8 @@ class Issue24Test extends ZipTestCase
|
||||
|
||||
static::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$stream = fopen('dummyfs://localhost/' . $this->outputFilename, 'rb');
|
||||
$uri = self::PROTO_DUMMYFS . '://localhost/' . $this->outputFilename;
|
||||
$stream = fopen($uri, 'rb');
|
||||
static::assertNotFalse($stream);
|
||||
$zip->openFromStream($stream);
|
||||
static::assertSame($zip->getListFiles(), ['file.txt']);
|
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Internal;
|
||||
|
||||
/**
|
||||
* Try to load using dummy stream.
|
||||
*/
|
||||
class DummyFileSystemStream
|
||||
{
|
||||
/** @var resource */
|
||||
private $fp;
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $mode
|
||||
* @param $options
|
||||
* @param $opened_path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function stream_open($path, $mode, $options, &$opened_path)
|
||||
{
|
||||
$parsedUrl = parse_url($path);
|
||||
$path = $parsedUrl['path'];
|
||||
$this->fp = fopen($path, $mode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $count
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function stream_read($count)
|
||||
{
|
||||
return fread($this->fp, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|int
|
||||
*/
|
||||
public function stream_tell()
|
||||
{
|
||||
return ftell($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function stream_eof()
|
||||
{
|
||||
return feof($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $offset
|
||||
* @param $whence
|
||||
*/
|
||||
public function stream_seek($offset, $whence)
|
||||
{
|
||||
fseek($this->fp, $offset, $whence);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function stream_stat()
|
||||
{
|
||||
return fstat($this->fp);
|
||||
}
|
||||
}
|
@@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\Crc32Exception;
|
||||
use PhpZip\Exception\RuntimeException;
|
||||
use PhpZip\Exception\ZipAuthenticationException;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Some tests from the official extension of php-zip.
|
||||
@@ -25,7 +26,7 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
*/
|
||||
public function testBinaryNull()
|
||||
{
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/binarynull.zip';
|
||||
$filename = __DIR__ . '/resources/pecl/binarynull.zip';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($filename);
|
||||
@@ -48,7 +49,7 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
*/
|
||||
public function testBug8009()
|
||||
{
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/bug8009.zip';
|
||||
$filename = __DIR__ . '/resources/pecl/bug8009.zip';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($filename);
|
||||
@@ -95,7 +96,7 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
public function provideBug40228()
|
||||
{
|
||||
return [
|
||||
[__DIR__ . '/php-zip-ext-test-resources/bug40228.zip'],
|
||||
[__DIR__ . '/resources/pecl/bug40228.zip'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(Crc32Exception::class, 'file1');
|
||||
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/bug49072.zip';
|
||||
$filename = __DIR__ . '/resources/pecl/bug49072.zip';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($filename);
|
||||
@@ -134,11 +135,11 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
} else { // php 64 bit
|
||||
$this->setExpectedException(
|
||||
ZipAuthenticationException::class,
|
||||
'nvalid password for zip entry "bug70752.txt"'
|
||||
'Invalid password'
|
||||
);
|
||||
}
|
||||
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/bug70752.zip';
|
||||
$filename = __DIR__ . '/resources/pecl/bug70752.zip';
|
||||
|
||||
static::assertTrue(mkdir($this->outputDirname, 0755, true));
|
||||
|
||||
@@ -151,9 +152,10 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
static::markTestIncomplete('failed test');
|
||||
} catch (ZipException $exception) {
|
||||
static::assertFileNotExists($this->outputDirname . '/bug70752.txt');
|
||||
$zipFile->close();
|
||||
|
||||
throw $exception;
|
||||
} finally {
|
||||
$zipFile->close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,9 +168,9 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
*/
|
||||
public function testPecl12414()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Corrupt zip file. Cannot read central dir entry.');
|
||||
$this->setExpectedException(ZipException::class, 'Corrupt zip file. Cannot read zip entry.');
|
||||
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/pecl12414.zip';
|
||||
$filename = __DIR__ . '/resources/pecl/pecl12414.zip';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($filename);
|
100
tests/SlowTests/Zip64Test.php
Normal file
100
tests/SlowTests/Zip64Test.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests\SlowTests;
|
||||
|
||||
use PhpZip\Constants\ZipCompressionMethod;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Tests\ZipTestCase;
|
||||
use PhpZip\Util\FilesUtil;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @large
|
||||
*/
|
||||
class Zip64Test extends ZipTestCase
|
||||
{
|
||||
/**
|
||||
* @throws ZipException
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testCreateLargeZip64File()
|
||||
{
|
||||
if (\PHP_INT_SIZE === 4) { // php 32 bit
|
||||
static::markTestSkipped('Only php-64 bit.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self::existsProgram('fallocate')) {
|
||||
static::markTestSkipped('Cannot find the program "fallocate" for the test');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$basedir = \dirname($this->outputFilename);
|
||||
$tmpLargeFile = $basedir . '/large_bin_file.bin';
|
||||
|
||||
$sizeLargeBinFile = (int) (4.2 * 1024 * 1024 * 1024);
|
||||
$needFreeSpace = $sizeLargeBinFile * 4;
|
||||
$diskFreeSpace = disk_free_space($basedir);
|
||||
|
||||
if ($needFreeSpace > $diskFreeSpace) {
|
||||
static::markTestIncomplete(
|
||||
sprintf(
|
||||
'Not enough disk space for the test. Need to free %s',
|
||||
FilesUtil::humanSize($needFreeSpace - $diskFreeSpace)
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$commandCreateLargeBinFile = 'fallocate -l ' . escapeshellarg($sizeLargeBinFile) . ' ' . escapeshellarg($tmpLargeFile);
|
||||
|
||||
exec($commandCreateLargeBinFile, $output, $returnCode);
|
||||
|
||||
if ($returnCode !== 0) {
|
||||
static::markTestIncomplete('Cannot create large file. Error code: ' . $returnCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile
|
||||
->addFile($tmpLargeFile, 'large_file1.bin', ZipCompressionMethod::STORED)
|
||||
->addFile($tmpLargeFile, 'large_file2.bin', ZipCompressionMethod::DEFLATED)
|
||||
->saveAsFile($this->outputFilename)
|
||||
->close()
|
||||
;
|
||||
|
||||
if (is_file($tmpLargeFile)) {
|
||||
unlink($tmpLargeFile);
|
||||
}
|
||||
|
||||
self::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
if (!is_dir($this->outputDirname)) {
|
||||
mkdir($this->outputDirname, 0755, true);
|
||||
}
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$zipFile->extractTo($this->outputDirname);
|
||||
|
||||
static::assertTrue(is_file($this->outputDirname . '/large_file1.bin'));
|
||||
static::assertTrue(is_file($this->outputDirname . '/large_file2.bin'));
|
||||
|
||||
$zipFile->deleteFromName('large_file1.bin');
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
|
||||
self::assertCorrectZipArchive($this->outputFilename);
|
||||
} finally {
|
||||
if (is_file($tmpLargeFile)) {
|
||||
unlink($tmpLargeFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class Zip64Test.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @large
|
||||
* @medium
|
||||
*/
|
||||
class Zip64Test extends ZipTestCase
|
||||
{
|
||||
@@ -17,7 +20,7 @@ class Zip64Test extends ZipTestCase
|
||||
*
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testCreateAndOpenZip64Ext()
|
||||
public function testOver65535FilesInZip()
|
||||
{
|
||||
$countFiles = 0xffff + 1;
|
||||
|
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Constants\ZipCompressionMethod;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Test ZipAlign.
|
||||
@@ -54,7 +56,7 @@ class ZipAlignTest extends ZipTestCase
|
||||
$zipFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
random_bytes(mt_rand(100, 4096)),
|
||||
ZipFile::METHOD_STORED
|
||||
ZipCompressionMethod::STORED
|
||||
);
|
||||
}
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
@@ -96,7 +98,7 @@ class ZipAlignTest extends ZipTestCase
|
||||
$zipFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
random_bytes(mt_rand(100, 4096)),
|
||||
ZipFile::METHOD_STORED
|
||||
ZipCompressionMethod::STORED
|
||||
);
|
||||
}
|
||||
$zipFile->setZipAlign(4);
|
||||
@@ -125,7 +127,7 @@ class ZipAlignTest extends ZipTestCase
|
||||
$zipFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
random_bytes(mt_rand(100, 4096)),
|
||||
ZipFile::METHOD_STORED
|
||||
ZipCompressionMethod::STORED
|
||||
);
|
||||
}
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
@@ -151,8 +153,8 @@ class ZipAlignTest extends ZipTestCase
|
||||
'entry_new_' . ($isStored ? 'stored' : 'deflated') . '_' . $i . '.txt',
|
||||
random_bytes(mt_rand(100, 4096)),
|
||||
$isStored ?
|
||||
ZipFile::METHOD_STORED :
|
||||
ZipFile::METHOD_DEFLATED
|
||||
ZipCompressionMethod::STORED :
|
||||
ZipCompressionMethod::DEFLATED
|
||||
);
|
||||
}
|
||||
$zipFile->setZipAlign(4);
|
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Tests\Internal\ZipFileExtended;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -16,11 +17,13 @@ class ZipEventTest extends ZipTestCase
|
||||
*/
|
||||
public function testBeforeSave()
|
||||
{
|
||||
$zipFile = new Internal\ZipFileExtended();
|
||||
$zipFile = new ZipFileExtended();
|
||||
$zipFile->openFile(__DIR__ . '/resources/apk.zip');
|
||||
static::assertTrue(isset($zipFile['META-INF/MANIFEST.MF']));
|
||||
static::assertTrue(isset($zipFile['META-INF/CERT.SF']));
|
||||
static::assertTrue(isset($zipFile['META-INF/CERT.RSA']));
|
||||
// the "META-INF/" folder will be deleted when saved
|
||||
// in the ZipFileExtended::onBeforeSave() method
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
static::assertFalse(isset($zipFile['META-INF/MANIFEST.MF']));
|
||||
static::assertFalse(isset($zipFile['META-INF/CERT.SF']));
|
||||
@@ -28,11 +31,6 @@ class ZipEventTest extends ZipTestCase
|
||||
$zipFile->close();
|
||||
|
||||
static::assertCorrectZipArchive($this->outputFilename);
|
||||
$result = static::assertVerifyZipAlign($this->outputFilename);
|
||||
|
||||
if ($result !== null) {
|
||||
static::assertTrue($result);
|
||||
}
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
static::assertFalse(isset($zipFile['META-INF/MANIFEST.MF']));
|
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Util\Iterator\IgnoreFilesFilterIterator;
|
||||
use PhpZip\Util\Iterator\IgnoreFilesRecursiveFilterIterator;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Test add directory to zip archive.
|
||||
@@ -13,82 +14,8 @@ use PhpZip\Util\Iterator\IgnoreFilesRecursiveFilterIterator;
|
||||
*
|
||||
* @small
|
||||
*/
|
||||
class ZipFileAddDirTest extends ZipTestCase
|
||||
class ZipFileAddDirTest extends ZipFileSetTestCase
|
||||
{
|
||||
protected static $files = [
|
||||
'.hidden' => 'Hidden file',
|
||||
'text file.txt' => 'Text file',
|
||||
'Текстовый документ.txt' => 'Текстовый документ',
|
||||
'empty dir/' => null,
|
||||
'empty dir2/ещё пустой каталог/' => null,
|
||||
'catalog/New File' => 'New Catalog File',
|
||||
'catalog/New File 2' => 'New Catalog File 2',
|
||||
'catalog/Empty Dir/' => null,
|
||||
'category/list.txt' => 'Category list',
|
||||
'category/Pictures/128x160/Car/01.jpg' => 'File 01.jpg',
|
||||
'category/Pictures/128x160/Car/02.jpg' => 'File 02.jpg',
|
||||
'category/Pictures/240x320/Car/01.jpg' => 'File 01.jpg',
|
||||
'category/Pictures/240x320/Car/02.jpg' => 'File 02.jpg',
|
||||
];
|
||||
|
||||
/**
|
||||
* Before test.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->fillDirectory();
|
||||
}
|
||||
|
||||
protected function fillDirectory()
|
||||
{
|
||||
foreach (self::$files as $name => $content) {
|
||||
$fullName = $this->outputDirname . '/' . $name;
|
||||
|
||||
if ($content === null) {
|
||||
if (!is_dir($fullName)) {
|
||||
mkdir($fullName, 0755, true);
|
||||
}
|
||||
} else {
|
||||
$dirname = \dirname($fullName);
|
||||
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0755, true);
|
||||
}
|
||||
file_put_contents($fullName, $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ZipFile $zipFile
|
||||
* @param array $actualResultFiles
|
||||
* @param string $localPath
|
||||
*/
|
||||
protected static function assertFilesResult(
|
||||
ZipFile $zipFile,
|
||||
array $actualResultFiles = [],
|
||||
$localPath = '/'
|
||||
) {
|
||||
$localPath = rtrim($localPath, '/');
|
||||
$localPath = empty($localPath) ? '' : $localPath . '/';
|
||||
static::assertCount(\count($zipFile), $actualResultFiles);
|
||||
$actualResultFiles = array_flip($actualResultFiles);
|
||||
|
||||
foreach (self::$files as $file => $content) {
|
||||
$zipEntryName = $localPath . $file;
|
||||
|
||||
if (isset($actualResultFiles[$file])) {
|
||||
static::assertTrue(isset($zipFile[$zipEntryName]));
|
||||
static::assertSame($zipFile[$zipEntryName], $content);
|
||||
unset($actualResultFiles[$file]);
|
||||
} else {
|
||||
static::assertFalse(isset($zipFile[$zipEntryName]));
|
||||
}
|
||||
}
|
||||
static::assertEmpty($actualResultFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ZipException
|
||||
*/
|
||||
@@ -111,6 +38,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
],
|
||||
$localPath
|
||||
);
|
||||
@@ -137,6 +65,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
]
|
||||
);
|
||||
$zipFile->close();
|
||||
@@ -166,6 +95,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
],
|
||||
$localPath
|
||||
);
|
||||
@@ -196,6 +126,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
]
|
||||
);
|
||||
$zipFile->close();
|
||||
@@ -267,6 +198,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
$ignoreFiles = [
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
];
|
||||
|
||||
$directoryIterator = new \DirectoryIterator($this->outputDirname);
|
||||
@@ -302,6 +234,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'empty dir2/ещё пустой каталог/',
|
||||
'list.txt',
|
||||
'category/Pictures/240x320',
|
||||
'LoremIpsum.txt',
|
||||
];
|
||||
|
||||
$directoryIterator = new \RecursiveDirectoryIterator($this->outputDirname);
|
||||
@@ -354,6 +287,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
[
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'LoremIpsum.txt',
|
||||
],
|
||||
$localPath
|
||||
);
|
||||
@@ -387,6 +321,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'category/Pictures/128x160/Car/02.jpg',
|
||||
'category/Pictures/240x320/Car/01.jpg',
|
||||
'category/Pictures/240x320/Car/02.jpg',
|
||||
'LoremIpsum.txt',
|
||||
],
|
||||
$localPath
|
||||
);
|
||||
@@ -415,6 +350,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
[
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'LoremIpsum.txt',
|
||||
],
|
||||
$localPath
|
||||
);
|
||||
@@ -444,6 +380,7 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'category/list.txt',
|
||||
'LoremIpsum.txt',
|
||||
'category/Pictures/128x160/Car/01.jpg',
|
||||
'category/Pictures/128x160/Car/02.jpg',
|
||||
'category/Pictures/240x320/Car/01.jpg',
|
91
tests/ZipFileSetTestCase.php
Normal file
91
tests/ZipFileSetTestCase.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Util\StringUtil;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipFileSetTestCase.
|
||||
*/
|
||||
abstract class ZipFileSetTestCase extends ZipTestCase
|
||||
{
|
||||
protected static $files = [
|
||||
'.hidden' => 'Hidden file',
|
||||
'text file.txt' => 'Text file',
|
||||
'Текстовый документ.txt' => 'Текстовый документ',
|
||||
'LoremIpsum.txt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
|
||||
'empty dir/' => '',
|
||||
'empty dir2/ещё пустой каталог/' => '',
|
||||
'catalog/New File' => 'New Catalog File',
|
||||
'catalog/New File 2' => 'New Catalog File 2',
|
||||
'catalog/Empty Dir/' => '',
|
||||
'category/list.txt' => 'Category list',
|
||||
'category/Pictures/128x160/Car/01.jpg' => 'File 01.jpg',
|
||||
'category/Pictures/128x160/Car/02.jpg' => 'File 02.jpg',
|
||||
'category/Pictures/240x320/Car/01.jpg' => 'File 01.jpg',
|
||||
'category/Pictures/240x320/Car/02.jpg' => 'File 02.jpg',
|
||||
];
|
||||
|
||||
/**
|
||||
* Before test.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->fillDirectory();
|
||||
}
|
||||
|
||||
protected function fillDirectory()
|
||||
{
|
||||
foreach (self::$files as $name => $content) {
|
||||
$fullName = $this->outputDirname . '/' . $name;
|
||||
|
||||
if (StringUtil::endsWith($name, '/')) {
|
||||
if (!is_dir($fullName) && !mkdir($fullName, 0755, true) && !is_dir($fullName)) {
|
||||
throw new \RuntimeException(sprintf('Directory "%s" was not created', $fullName));
|
||||
}
|
||||
} else {
|
||||
$dirname = \dirname($fullName);
|
||||
|
||||
if (!is_dir($dirname) && !mkdir($dirname, 0755, true) && !is_dir($dirname)) {
|
||||
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dirname));
|
||||
}
|
||||
file_put_contents($fullName, $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ZipFile $zipFile
|
||||
* @param array $actualResultFiles
|
||||
* @param string $localPath
|
||||
*/
|
||||
protected static function assertFilesResult(
|
||||
ZipFile $zipFile,
|
||||
array $actualResultFiles = [],
|
||||
$localPath = '/'
|
||||
) {
|
||||
$localPath = rtrim($localPath, '/');
|
||||
$localPath = empty($localPath) ? '' : $localPath . '/';
|
||||
static::assertCount(\count($zipFile), $actualResultFiles);
|
||||
$actualResultFiles = array_flip($actualResultFiles);
|
||||
|
||||
foreach (self::$files as $file => $content) {
|
||||
$zipEntryName = $localPath . $file;
|
||||
|
||||
if (isset($actualResultFiles[$file])) {
|
||||
static::assertTrue(isset($zipFile[$zipEntryName]));
|
||||
static::assertSame(
|
||||
$zipFile[$zipEntryName],
|
||||
$content,
|
||||
sprintf('The content of the entry "%s" is not as expected.', $zipEntryName)
|
||||
);
|
||||
unset($actualResultFiles[$file]);
|
||||
} else {
|
||||
static::assertFalse(isset($zipFile[$zipEntryName]));
|
||||
}
|
||||
}
|
||||
static::assertEmpty($actualResultFiles);
|
||||
}
|
||||
}
|
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Constants\ZipCompressionLevel;
|
||||
use PhpZip\Constants\ZipCompressionMethod;
|
||||
use PhpZip\Constants\ZipPlatform;
|
||||
use PhpZip\Exception\InvalidArgumentException;
|
||||
use PhpZip\Exception\ZipEntryNotFoundException;
|
||||
use PhpZip\Exception\ZipException;
|
||||
@@ -9,6 +12,7 @@ use PhpZip\Exception\ZipUnsupportMethodException;
|
||||
use PhpZip\Model\ZipEntry;
|
||||
use PhpZip\Model\ZipInfo;
|
||||
use PhpZip\Util\FilesUtil;
|
||||
use PhpZip\ZipFile;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
|
||||
@@ -39,10 +43,7 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'can\'t open');
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
if (posix_getuid() === 0) {
|
||||
static::markTestSkipped('Skip the test for a user with root privileges');
|
||||
|
||||
if (static::skipTestForRootUser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFileEmptyFile()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Invalid zip file');
|
||||
$this->setExpectedException(ZipException::class, 'Corrupt zip file');
|
||||
|
||||
static::assertNotFalse(touch($this->outputFilename));
|
||||
$zipFile = new ZipFile();
|
||||
@@ -73,7 +74,7 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(
|
||||
ZipException::class,
|
||||
'Expected Local File Header or (ZIP64) End Of Central Directory Record'
|
||||
'Invalid zip file. The end of the central directory could not be found.'
|
||||
);
|
||||
|
||||
static::assertNotFalse(file_put_contents($this->outputFilename, random_bytes(255)));
|
||||
@@ -111,7 +112,7 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(
|
||||
ZipException::class,
|
||||
'Expected Local File Header or (ZIP64) End Of Central Directory Record'
|
||||
'Invalid zip file. The end of the central directory could not be found.'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
@@ -143,7 +144,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFromStreamNullStream()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Invalid stream resource');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Stream must be a resource');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFromStream(null);
|
||||
@@ -154,7 +155,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFromStreamInvalidResourceType()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Invalid stream resource');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Stream must be a resource');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
/** @noinspection PhpParamsInspection */
|
||||
@@ -166,7 +167,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFromStreamInvalidResourceType2()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Invalid resource type - gd.');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Invalid resource type');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
|
||||
@@ -184,7 +185,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFromStreamInvalidResourceType3()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Invalid stream type - dir.');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Directory stream not supported');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFromStream(opendir(__DIR__));
|
||||
@@ -197,7 +198,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFromStreamNoSeekable()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Resource cannot seekable stream.');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'The stream wrapper type "http" is not supported');
|
||||
|
||||
if (!$fp = @fopen('http://localhost', 'rb')) {
|
||||
if (!$fp = @fopen('http://example.org', 'rb')) {
|
||||
@@ -216,7 +217,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testOpenFromStreamEmptyContents()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Invalid zip file');
|
||||
$this->setExpectedException(ZipException::class, 'Corrupt zip file');
|
||||
|
||||
$fp = fopen($this->outputFilename, 'w+b');
|
||||
$zipFile = new ZipFile();
|
||||
@@ -231,7 +232,7 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(
|
||||
ZipException::class,
|
||||
'Expected Local File Header or (ZIP64) End Of Central Directory Record'
|
||||
'Invalid zip file. The end of the central directory could not be found.'
|
||||
);
|
||||
|
||||
$fp = fopen($this->outputFilename, 'w+b');
|
||||
@@ -301,7 +302,7 @@ class ZipFileTest extends ZipTestCase
|
||||
$fileExpected = $this->outputDirname . \DIRECTORY_SEPARATOR . 'file_expected.zip';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addDirRecursive(__DIR__ . '/../../src');
|
||||
$zipFile->addDirRecursive(__DIR__ . '/../src');
|
||||
$sourceCount = $zipFile->count();
|
||||
static::assertTrue($sourceCount > 0);
|
||||
$zipFile
|
||||
@@ -344,9 +345,9 @@ class ZipFileTest extends ZipTestCase
|
||||
public function testCreateArchiveAndAddFiles()
|
||||
{
|
||||
$outputFromString = file_get_contents(__FILE__);
|
||||
$outputFromString2 = file_get_contents(\dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'README.md');
|
||||
$outputFromFile = file_get_contents(\dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'phpunit.xml');
|
||||
$outputFromStream = file_get_contents(\dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'composer.json');
|
||||
$outputFromString2 = file_get_contents(\dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'README.md');
|
||||
$outputFromFile = file_get_contents(\dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'phpunit.xml');
|
||||
$outputFromStream = file_get_contents(\dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'composer.json');
|
||||
|
||||
$filenameFromString = basename(__FILE__);
|
||||
$filenameFromString2 = 'test_file.txt';
|
||||
@@ -451,7 +452,7 @@ class ZipFileTest extends ZipTestCase
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$info = $zipFile->getEntryInfo($basename);
|
||||
static::assertSame($info->getMethodName(), 'No compression');
|
||||
static::assertSame($info->getMethodName(), 'Stored');
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
@@ -562,7 +563,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testDeleteFromName()
|
||||
{
|
||||
$inputDir = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR;
|
||||
$inputDir = \dirname(__DIR__) . \DIRECTORY_SEPARATOR;
|
||||
$deleteEntryName = 'composer.json';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
@@ -585,7 +586,7 @@ class ZipFileTest extends ZipTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\ZipEntryNotFoundException
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testDeleteNewEntry()
|
||||
@@ -615,6 +616,18 @@ class ZipFileTest extends ZipTestCase
|
||||
$zipFile->deleteFromName('entry');
|
||||
}
|
||||
|
||||
public function testCatchNotFoundEntry()
|
||||
{
|
||||
$entryName = 'entry';
|
||||
$zipFile = new ZipFile();
|
||||
|
||||
try {
|
||||
$zipFile->getEntry($entryName);
|
||||
} catch (ZipEntryNotFoundException $e) {
|
||||
static::assertSame($e->getEntryName(), $entryName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete zip entries from glob pattern.
|
||||
*
|
||||
@@ -622,7 +635,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testDeleteFromGlob()
|
||||
{
|
||||
$inputDir = \dirname(\dirname(__DIR__));
|
||||
$inputDir = \dirname(__DIR__);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFilesFromGlobRecursive($inputDir, '**.{xml,json,md}', '/');
|
||||
@@ -677,7 +690,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testDeleteFromRegex()
|
||||
{
|
||||
$inputDir = \dirname(\dirname(__DIR__));
|
||||
$inputDir = \dirname(__DIR__);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFilesFromRegexRecursive($inputDir, '~\.(xml|json)$~i', 'Path');
|
||||
@@ -726,7 +739,7 @@ class ZipFileTest extends ZipTestCase
|
||||
public function testDeleteAll()
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addDirRecursive(\dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'src');
|
||||
$zipFile->addDirRecursive(\dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'src');
|
||||
static::assertTrue($zipFile->count() > 0);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
@@ -880,7 +893,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testVeryLongEntryComment()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Comment too long');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Comment too long');
|
||||
|
||||
$comment = 'Very long comment' . \PHP_EOL .
|
||||
'Очень длинный комментарий' . \PHP_EOL;
|
||||
@@ -913,21 +926,21 @@ class ZipFileTest extends ZipTestCase
|
||||
$entries = [
|
||||
'1' => [
|
||||
'data' => random_bytes(255),
|
||||
'method' => ZipFile::METHOD_STORED,
|
||||
'expected' => 'No compression',
|
||||
'method' => ZipCompressionMethod::STORED,
|
||||
'expected' => 'Stored',
|
||||
],
|
||||
'2' => [
|
||||
'data' => random_bytes(255),
|
||||
'method' => ZipFile::METHOD_DEFLATED,
|
||||
'expected' => 'Deflate',
|
||||
'method' => ZipCompressionMethod::DEFLATED,
|
||||
'expected' => 'Deflated',
|
||||
],
|
||||
];
|
||||
|
||||
if (\extension_loaded('bz2')) {
|
||||
$entries['3'] = [
|
||||
'data' => random_bytes(255),
|
||||
'method' => ZipFile::METHOD_BZIP2,
|
||||
'expected' => 'Bzip2',
|
||||
'method' => ZipCompressionMethod::BZIP2,
|
||||
'expected' => 'BZIP2',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -942,7 +955,7 @@ class ZipFileTest extends ZipTestCase
|
||||
static::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$zipFile->setCompressionLevel(ZipFile::LEVEL_BEST_COMPRESSION);
|
||||
$zipFile->setCompressionLevel(ZipCompressionLevel::MAXIMUM);
|
||||
$zipAllInfo = $zipFile->getAllInfo();
|
||||
|
||||
foreach ($zipAllInfo as $entryName => $info) {
|
||||
@@ -954,26 +967,34 @@ class ZipFileTest extends ZipTestCase
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
public function testSetInvalidCompressionLevel()
|
||||
/**
|
||||
* @dataProvider provideInvalidCompressionLevels
|
||||
*
|
||||
* @param int $compressionLevel
|
||||
*/
|
||||
public function testSetInvalidCompressionLevel($compressionLevel)
|
||||
{
|
||||
$this->setExpectedException(
|
||||
InvalidArgumentException::class,
|
||||
'Invalid compression level. Minimum level -1. Maximum level 9'
|
||||
'Invalid compression level. Minimum level 1. Maximum level 9'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->setCompressionLevel(-2);
|
||||
$zipFile['file 1'] = 'contents';
|
||||
$zipFile->setCompressionLevel($compressionLevel);
|
||||
}
|
||||
|
||||
public function testSetInvalidCompressionLevel2()
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function provideInvalidCompressionLevels()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
InvalidArgumentException::class,
|
||||
'Invalid compression level. Minimum level -1. Maximum level 9'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->setCompressionLevel(10);
|
||||
return [
|
||||
[-10],
|
||||
[-2],
|
||||
[10],
|
||||
[0xffff],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1125,10 +1146,7 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Destination is not writable directory');
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
if (posix_getuid() === 0) {
|
||||
static::markTestSkipped('Skip the test for a user with root privileges');
|
||||
|
||||
if (static::skipTestForRootUser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1149,7 +1167,10 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFromArrayAccessNullName()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'entryName is null');
|
||||
$this->setExpectedException(
|
||||
InvalidArgumentException::class,
|
||||
'Key must not be null, but must contain the name of the zip entry.'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile[null] = 'content';
|
||||
@@ -1160,7 +1181,10 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFromArrayAccessEmptyName()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'entryName is empty');
|
||||
$this->setExpectedException(
|
||||
InvalidArgumentException::class,
|
||||
'Key is empty, but must contain the name of the zip entry.'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile[''] = 'content';
|
||||
@@ -1193,10 +1217,14 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFromStringUnsupportedMethod()
|
||||
{
|
||||
$this->setExpectedException(ZipUnsupportMethodException::class, 'Unsupported compression method');
|
||||
$this->setExpectedException(
|
||||
ZipUnsupportMethodException::class,
|
||||
'Compression method 99 (AES Encryption) is not supported.'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'contents', ZipEntry::METHOD_WINZIP_AES);
|
||||
$zipFile->addFromString('file', 'contents', ZipCompressionMethod::WINZIP_AES);
|
||||
$zipFile->outputAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1235,8 +1263,8 @@ class ZipFileTest extends ZipTestCase
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$infoStored = $zipFile->getEntryInfo(basename($fileStored));
|
||||
$infoDeflated = $zipFile->getEntryInfo(basename($fileDeflated));
|
||||
static::assertSame($infoStored->getMethodName(), 'No compression');
|
||||
static::assertSame($infoDeflated->getMethodName(), 'Deflate');
|
||||
static::assertSame($infoStored->getMethodName(), 'Stored');
|
||||
static::assertSame($infoDeflated->getMethodName(), 'Deflated');
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
@@ -1270,12 +1298,16 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFromStreamUnsupportedMethod()
|
||||
{
|
||||
$this->setExpectedException(ZipUnsupportMethodException::class, 'Unsupported method');
|
||||
$this->setExpectedException(
|
||||
ZipUnsupportMethodException::class,
|
||||
'Compression method 99 (AES Encryption) is not supported.'
|
||||
);
|
||||
|
||||
$handle = fopen(__FILE__, 'rb');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromStream($handle, basename(__FILE__), ZipEntry::METHOD_WINZIP_AES);
|
||||
$zipFile->addFromStream($handle, basename(__FILE__), ZipCompressionMethod::WINZIP_AES);
|
||||
$zipFile->outputAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1306,8 +1338,8 @@ class ZipFileTest extends ZipTestCase
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$infoStored = $zipFile->getEntryInfo(basename($fileStored));
|
||||
$infoDeflated = $zipFile->getEntryInfo(basename($fileDeflated));
|
||||
static::assertSame($infoStored->getMethodName(), 'No compression');
|
||||
static::assertSame($infoDeflated->getMethodName(), 'Deflate');
|
||||
static::assertSame($infoStored->getMethodName(), 'Stored');
|
||||
static::assertSame($infoDeflated->getMethodName(), 'Deflated');
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
@@ -1316,7 +1348,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFileNullFileName()
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'file is null');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Filename is null');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFile(null);
|
||||
@@ -1327,7 +1359,7 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFileCantExists()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'does not exist');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'File path/to/file is not readable');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFile('path/to/file');
|
||||
@@ -1338,10 +1370,14 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFileUnsupportedMethod()
|
||||
{
|
||||
$this->setExpectedException(ZipUnsupportMethodException::class, 'Unsupported compression method 99');
|
||||
$this->setExpectedException(
|
||||
ZipUnsupportMethodException::class,
|
||||
'Compression method 99 (AES Encryption) is not supported.'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFile(__FILE__, null, ZipEntry::METHOD_WINZIP_AES);
|
||||
$zipFile->addFile(__FILE__, null, ZipCompressionMethod::WINZIP_AES);
|
||||
$zipFile->outputAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1349,12 +1385,9 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testAddFileCantOpen()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'file could not be read');
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
if (posix_getuid() === 0) {
|
||||
static::markTestSkipped('Skip the test for a user with root privileges');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'is not readable');
|
||||
|
||||
if (static::skipTestForRootUser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1670,10 +1703,7 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'can not open from write');
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
if (posix_getuid() === 0) {
|
||||
static::markTestSkipped('Skip the test for a user with root privileges');
|
||||
|
||||
if (static::skipTestForRootUser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1700,17 +1730,21 @@ class ZipFileTest extends ZipTestCase
|
||||
$files['file' . $i . '.txt'] = random_bytes(255);
|
||||
}
|
||||
|
||||
$methods = [ZipFile::METHOD_STORED, ZipFile::METHOD_DEFLATED];
|
||||
$compressionMethods = [ZipCompressionMethod::STORED, ZipCompressionMethod::DEFLATED];
|
||||
|
||||
if (\extension_loaded('bz2')) {
|
||||
$methods[] = ZipFile::METHOD_BZIP2;
|
||||
$compressionMethods[] = ZipCompressionMethod::BZIP2;
|
||||
}
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->setCompressionLevel(ZipFile::LEVEL_BEST_SPEED);
|
||||
$zipFile->setCompressionLevel(ZipCompressionLevel::SUPER_FAST);
|
||||
|
||||
$i = 0;
|
||||
$countMethods = \count($compressionMethods);
|
||||
|
||||
foreach ($files as $entryName => $content) {
|
||||
$zipFile->addFromString($entryName, $content, $methods[array_rand($methods)]);
|
||||
$compressionMethod = $compressionMethods[$i++ % $countMethods];
|
||||
$zipFile->addFromString($entryName, $content, $compressionMethod);
|
||||
}
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
@@ -1804,7 +1838,7 @@ class ZipFileTest extends ZipTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\ZipEntryNotFoundException
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
* @throws \Exception
|
||||
*/
|
||||
@@ -1815,16 +1849,15 @@ class ZipFileTest extends ZipTestCase
|
||||
$zipFile->addFromString('file', 'content', ZipEntry::UNKNOWN);
|
||||
$zipFile->addFromString('file2', base64_encode(random_bytes(512)), ZipEntry::UNKNOWN);
|
||||
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Unknown');
|
||||
static::assertSame($zipFile->getEntryInfo('file2')->getMethodName(), 'Unknown');
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Stored');
|
||||
static::assertSame($zipFile->getEntryInfo('file2')->getMethodName(), 'Deflated');
|
||||
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'No compression');
|
||||
static::assertSame($zipFile->getEntryInfo('file2')->getMethodName(), 'Deflate');
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Stored');
|
||||
static::assertSame($zipFile->getEntryInfo('file2')->getMethodName(), 'Deflated');
|
||||
|
||||
$zipFile->close();
|
||||
}
|
||||
@@ -1986,21 +2019,23 @@ class ZipFileTest extends ZipTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideCompressionLevels
|
||||
*
|
||||
* @param int $compressionLevel
|
||||
*
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testCompressionLevel()
|
||||
public function testCompressionLevel($compressionLevel)
|
||||
{
|
||||
$fileContent = random_bytes(512);
|
||||
$entryName = 'file.txt';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile
|
||||
->addFromString('file', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file', ZipFile::LEVEL_BEST_COMPRESSION)
|
||||
->addFromString('file2', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file2', ZipFile::LEVEL_FAST)
|
||||
->addFromString('file3', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file3', ZipFile::LEVEL_SUPER_FAST)
|
||||
->addFromString('file4', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file4', ZipFile::LEVEL_DEFAULT_COMPRESSION)
|
||||
->addFromString($entryName, $fileContent, ZipCompressionMethod::DEFLATED)
|
||||
->setCompressionLevelEntry($entryName, $compressionLevel)
|
||||
->saveAsFile($this->outputFilename)
|
||||
->close()
|
||||
;
|
||||
@@ -2008,29 +2043,25 @@ class ZipFileTest extends ZipTestCase
|
||||
static::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file')
|
||||
->getCompressionLevel(),
|
||||
ZipFile::LEVEL_BEST_COMPRESSION
|
||||
);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file2')
|
||||
->getCompressionLevel(),
|
||||
ZipFile::LEVEL_FAST
|
||||
);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file3')
|
||||
->getCompressionLevel(),
|
||||
ZipFile::LEVEL_SUPER_FAST
|
||||
);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file4')
|
||||
->getCompressionLevel(),
|
||||
ZipFile::LEVEL_DEFAULT_COMPRESSION
|
||||
);
|
||||
static::assertSame($zipFile->getEntryContents($entryName), $fileContent);
|
||||
static::assertSame($zipFile->getEntry($entryName)->getCompressionLevel(), $compressionLevel);
|
||||
static::assertSame($zipFile->getEntryInfo($entryName)->getCompressionLevel(), $compressionLevel);
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function provideCompressionLevels()
|
||||
{
|
||||
return [
|
||||
[ZipCompressionLevel::MAXIMUM],
|
||||
[ZipCompressionLevel::NORMAL],
|
||||
[ZipCompressionLevel::FAST],
|
||||
[ZipCompressionLevel::SUPER_FAST],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ZipException
|
||||
*/
|
||||
@@ -2062,10 +2093,10 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$zipFile->addFromString('file' . $i, 'content', ZipFile::METHOD_DEFLATED);
|
||||
$zipFile->addFromString('file' . $i, 'content', ZipCompressionMethod::DEFLATED);
|
||||
}
|
||||
$zipFile
|
||||
->setCompressionLevel(ZipFile::LEVEL_BEST_SPEED)
|
||||
->setCompressionLevel(ZipCompressionLevel::SUPER_FAST)
|
||||
->saveAsFile($this->outputFilename)
|
||||
->close()
|
||||
;
|
||||
@@ -2077,7 +2108,7 @@ class ZipFileTest extends ZipTestCase
|
||||
array_walk(
|
||||
$infoList,
|
||||
function (ZipInfo $zipInfo) {
|
||||
$this->assertSame($zipInfo->getCompressionLevel(), ZipFile::LEVEL_BEST_SPEED);
|
||||
$this->assertSame($zipInfo->getCompressionLevel(), ZipCompressionLevel::SUPER_FAST);
|
||||
}
|
||||
);
|
||||
$zipFile->close();
|
||||
@@ -2090,17 +2121,17 @@ class ZipFileTest extends ZipTestCase
|
||||
public function testCompressionMethodEntry()
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'content', ZipFile::METHOD_STORED);
|
||||
$zipFile->addFromString('file', 'content', ZipCompressionMethod::STORED);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'No compression');
|
||||
$zipFile->setCompressionMethodEntry('file', ZipFile::METHOD_DEFLATED);
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Deflate');
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Stored');
|
||||
$zipFile->setCompressionMethodEntry('file', ZipCompressionMethod::DEFLATED);
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Deflated');
|
||||
|
||||
$zipFile->rewrite();
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Deflate');
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Deflated');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2108,11 +2139,15 @@ class ZipFileTest extends ZipTestCase
|
||||
*/
|
||||
public function testInvalidCompressionMethodEntry()
|
||||
{
|
||||
$this->setExpectedException(ZipUnsupportMethodException::class, 'Unsupported method');
|
||||
$this->setExpectedException(
|
||||
ZipUnsupportMethodException::class,
|
||||
'Compression method 99 (AES Encryption) is not supported.'
|
||||
);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'content', ZipFile::METHOD_STORED);
|
||||
$zipFile->addFromString('file', 'content', ZipCompressionMethod::STORED);
|
||||
$zipFile->setCompressionMethodEntry('file', 99);
|
||||
$zipFile->outputAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2268,4 +2303,90 @@ class ZipFileTest extends ZipTestCase
|
||||
['file.apk', null, 'application/vnd.android.package-archive', true, 'attachment'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGetEntryStream
|
||||
*
|
||||
* @param ZipFile $zipFile
|
||||
* @param string $entryName
|
||||
* @param string $contents
|
||||
*
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testReopenEntryStream(ZipFile $zipFile, $entryName, $contents)
|
||||
{
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$fp = $zipFile->getEntryStream($entryName);
|
||||
static::assertInternalType('resource', $fp);
|
||||
static::assertSame(stream_get_contents($fp), $contents);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideGetEntryStream()
|
||||
{
|
||||
$entryName = 'entry';
|
||||
$contents = random_bytes(1024);
|
||||
|
||||
$zipFileSpl = new ZipFile();
|
||||
$zipFileSpl->addSplFile(new \SplFileInfo(__FILE__), $entryName);
|
||||
|
||||
return [
|
||||
[(new ZipFile())->addFromString($entryName, $contents), $entryName, $contents],
|
||||
[(new ZipFile())->addFile(__FILE__, $entryName), $entryName, file_get_contents(__FILE__)],
|
||||
[
|
||||
(new ZipFile())->addFromStream(fopen(__FILE__, 'rb'), $entryName),
|
||||
$entryName,
|
||||
file_get_contents(__FILE__),
|
||||
],
|
||||
[$zipFileSpl, $entryName, file_get_contents(__FILE__)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testGetEntries()
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$zipFile->addFromString($i . '.txt', 'contents ' . $i);
|
||||
}
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$zipEntries = $zipFile->getEntries();
|
||||
static::assertCount(100, $zipEntries);
|
||||
|
||||
foreach ($zipEntries as $zipEntry) {
|
||||
static::assertInstanceOf(ZipEntry::class, $zipEntry);
|
||||
static::assertNotSame($zipEntry->getDosTime(), 0);
|
||||
$zipEntry->setDosTime(0);
|
||||
$zipEntry->setCreatedOS(ZipPlatform::OS_DOS);
|
||||
$zipEntry->setExtractedOS(ZipPlatform::OS_DOS);
|
||||
$zipEntry->setInternalAttributes(1);
|
||||
$zipEntry->setExternalAttributes(0);
|
||||
}
|
||||
$zipFile->rewrite();
|
||||
|
||||
self::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
foreach ($zipFile->getEntries() as $zipEntry) {
|
||||
static::assertSame($zipEntry->getDosTime(), 0);
|
||||
static::assertSame($zipEntry->getExtractedOS(), ZipPlatform::OS_DOS);
|
||||
static::assertSame($zipEntry->getCreatedOS(), ZipPlatform::OS_DOS);
|
||||
static::assertSame($zipEntry->getInternalAttributes(), 1);
|
||||
static::assertSame($zipEntry->getExternalAttributes(), 0);
|
||||
}
|
||||
$zipFile->close();
|
||||
}
|
||||
}
|
42
tests/ZipFinderTest.php
Normal file
42
tests/ZipFinderTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Constants\ZipCompressionMethod;
|
||||
use PhpZip\Constants\ZipOptions;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @small
|
||||
*/
|
||||
class ZipFinderTest extends ZipTestCase
|
||||
{
|
||||
/**
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testFinder()
|
||||
{
|
||||
$finder = (new Finder())
|
||||
->files()
|
||||
->name('*.php')
|
||||
->in(__DIR__)
|
||||
;
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromFinder(
|
||||
$finder,
|
||||
[
|
||||
ZipOptions::COMPRESSION_METHOD => ZipCompressionMethod::DEFLATED,
|
||||
]
|
||||
);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
|
||||
static::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
static::assertSame($finder->count(), $zipFile->count());
|
||||
$zipFile->close();
|
||||
}
|
||||
}
|
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PhpZip\Model\ZipEntryMatcher;
|
||||
use PhpZip\Model\ZipInfo;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* @internal
|
@@ -1,12 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Constants\ZipCompressionMethod;
|
||||
use PhpZip\Constants\ZipEncryptionMethod;
|
||||
use PhpZip\Exception\InvalidArgumentException;
|
||||
use PhpZip\Exception\RuntimeException;
|
||||
use PhpZip\Exception\ZipAuthenticationException;
|
||||
use PhpZip\Exception\ZipEntryNotFoundException;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Model\ZipInfo;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Tests with zip password.
|
||||
@@ -15,7 +19,7 @@ use PhpZip\Model\ZipInfo;
|
||||
*
|
||||
* @small
|
||||
*/
|
||||
class ZipPasswordTest extends ZipFileAddDirTest
|
||||
class ZipPasswordTest extends ZipFileSetTestCase
|
||||
{
|
||||
/**
|
||||
* Test archive password.
|
||||
@@ -36,17 +40,17 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$password = base64_encode(random_bytes(100));
|
||||
$badPassword = 'bad password';
|
||||
|
||||
// create encryption password with ZipCrypto
|
||||
// create encryption password with Traditional PKWARE encryption
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addDir(__DIR__);
|
||||
$zipFile->setPassword($password, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zipFile->setPassword($password, ZipEncryptionMethod::PKWARE);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
static::assertCorrectZipArchive($this->outputFilename, $password);
|
||||
|
||||
// check bad password for ZipCrypto
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
// check bad password for Traditional PKWARE encryption
|
||||
$zipFile->setReadPassword($badPassword);
|
||||
|
||||
foreach ($zipFile->getListFiles() as $entryName) {
|
||||
@@ -54,23 +58,23 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$zipFile[$entryName];
|
||||
static::fail('Expected Exception has not been raised.');
|
||||
} catch (ZipAuthenticationException $ae) {
|
||||
static::assertContains('Invalid password for zip entry', $ae->getMessage());
|
||||
static::assertContains('Invalid password', $ae->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// check correct password for ZipCrypto
|
||||
// check correct password for Traditional PKWARE encryption
|
||||
$zipFile->setReadPassword($password);
|
||||
|
||||
foreach ($zipFile->getAllInfo() as $info) {
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('ZipCrypto', $info->getMethodName());
|
||||
static::assertContains('Traditional PKWARE encryption', $info->getEncryptionMethodName());
|
||||
$decryptContent = $zipFile[$info->getName()];
|
||||
static::assertNotEmpty($decryptContent);
|
||||
static::assertContains('<?php', $decryptContent);
|
||||
}
|
||||
|
||||
// change encryption method to WinZip Aes and update file
|
||||
$zipFile->setPassword($password, ZipFile::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zipFile->setPassword($password, ZipEncryptionMethod::WINZIP_AES_256);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
@@ -78,6 +82,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
|
||||
// check from WinZip AES encryption
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
|
||||
// set bad password WinZip AES
|
||||
$zipFile->setReadPassword($badPassword);
|
||||
|
||||
@@ -95,7 +100,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
|
||||
foreach ($zipFile->getAllInfo() as $info) {
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('WinZip', $info->getMethodName());
|
||||
static::assertContains('Deflated', $info->getMethodName());
|
||||
static::assertContains('WinZip AES-256', $info->getEncryptionMethodName());
|
||||
$decryptContent = $zipFile[$info->getName()];
|
||||
static::assertNotEmpty($decryptContent);
|
||||
static::assertContains('<?php', $decryptContent);
|
||||
@@ -136,7 +142,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
|
||||
$zip = new ZipFile();
|
||||
$zip->addDirRecursive($this->outputDirname);
|
||||
$zip->setPassword($password, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPassword($password, ZipEncryptionMethod::PKWARE);
|
||||
$zip->saveAsFile($this->outputFilename);
|
||||
$zip->close();
|
||||
|
||||
@@ -149,7 +155,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
foreach ($zip->getAllInfo() as $info) {
|
||||
if (!$info->isFolder()) {
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('ZipCrypto', $info->getMethodName());
|
||||
static::assertContains('Traditional PKWARE encryption', $info->getEncryptionMethodName());
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
@@ -184,7 +190,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
if (!$info->isFolder()) {
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertSame($info->getEncryptionMethod(), $encryptionMethod);
|
||||
static::assertContains('WinZip AES-' . $bitSize, $info->getMethodName());
|
||||
static::assertContains('WinZip AES-' . $bitSize, $info->getEncryptionMethodName());
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
@@ -196,15 +202,14 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
public function winZipKeyStrengthProvider()
|
||||
{
|
||||
return [
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES_128, 128],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES_192, 192],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES, 256],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256, 256],
|
||||
[ZipEncryptionMethod::WINZIP_AES_128, 128],
|
||||
[ZipEncryptionMethod::WINZIP_AES_192, 192],
|
||||
[ZipEncryptionMethod::WINZIP_AES_256, 256],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\ZipEntryNotFoundException
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testEncryptionEntries()
|
||||
@@ -221,8 +226,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
|
||||
$zip = new ZipFile();
|
||||
$zip->addDir($this->outputDirname);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipFile::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipEncryptionMethod::PKWARE);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipEncryptionMethod::WINZIP_AES_256);
|
||||
$zip->saveAsFile($this->outputFilename);
|
||||
$zip->close();
|
||||
|
||||
@@ -236,16 +241,17 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
]
|
||||
);
|
||||
|
||||
$info = $zip->getEntryInfo('.hidden');
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('ZipCrypto', $info->getMethodName());
|
||||
static::assertContains('Traditional PKWARE encryption', $info->getEncryptionMethodName());
|
||||
|
||||
$info = $zip->getEntryInfo('text file.txt');
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('WinZip AES', $info->getMethodName());
|
||||
static::assertContains('WinZip AES', $info->getEncryptionMethodName());
|
||||
|
||||
static::assertFalse($zip->getEntryInfo('Текстовый документ.txt')->isEncrypted());
|
||||
static::assertFalse($zip->getEntryInfo('empty dir/')->isEncrypted());
|
||||
@@ -254,7 +260,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\ZipEntryNotFoundException
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testEncryptionEntriesWithDefaultPassword()
|
||||
@@ -273,8 +279,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$zip = new ZipFile();
|
||||
$zip->addDir($this->outputDirname);
|
||||
$zip->setPassword($defaultPassword);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipFile::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipEncryptionMethod::PKWARE);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipEncryptionMethod::WINZIP_AES_256);
|
||||
$zip->saveAsFile($this->outputFilename);
|
||||
$zip->close();
|
||||
|
||||
@@ -289,20 +295,21 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
'text file.txt',
|
||||
'Текстовый документ.txt',
|
||||
'empty dir/',
|
||||
'LoremIpsum.txt',
|
||||
]
|
||||
);
|
||||
|
||||
$info = $zip->getEntryInfo('.hidden');
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('ZipCrypto', $info->getMethodName());
|
||||
static::assertContains('Traditional PKWARE encryption', $info->getEncryptionMethodName());
|
||||
|
||||
$info = $zip->getEntryInfo('text file.txt');
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('WinZip AES', $info->getMethodName());
|
||||
static::assertContains('WinZip AES', $info->getEncryptionMethodName());
|
||||
|
||||
$info = $zip->getEntryInfo('Текстовый документ.txt');
|
||||
static::assertTrue($info->isEncrypted());
|
||||
static::assertContains('WinZip AES', $info->getMethodName());
|
||||
static::assertContains('WinZip AES', $info->getEncryptionMethodName());
|
||||
|
||||
static::assertFalse($zip->getEntryInfo('empty dir/')->isEncrypted());
|
||||
|
||||
@@ -314,17 +321,17 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
*/
|
||||
public function testSetEncryptionMethodInvalid()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Invalid encryption method');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Encryption method 9999 is not supported.');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$encryptionMethod = 9999;
|
||||
$zipFile->setPassword('pass', $encryptionMethod);
|
||||
$zipFile['entry'] = 'content';
|
||||
$zipFile->setPassword('pass', $encryptionMethod);
|
||||
$zipFile->outputAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\ZipEntryNotFoundException
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testEntryPassword()
|
||||
@@ -362,11 +369,11 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
*/
|
||||
public function testInvalidEncryptionMethodEntry()
|
||||
{
|
||||
$this->setExpectedException(ZipException::class, 'Invalid encryption method');
|
||||
$this->setExpectedException(InvalidArgumentException::class, 'Encryption method 99 is not supported.');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'content', ZipFile::METHOD_STORED);
|
||||
$zipFile->setPasswordEntry('file', 'pass', 99);
|
||||
$zipFile->addFromString('file', 'content', ZipCompressionMethod::STORED);
|
||||
$zipFile->setPasswordEntry('file', 'pass', ZipCompressionMethod::WINZIP_AES);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,11 +431,10 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$contents = str_pad('', 1000, 'test;test2;test3' . \PHP_EOL, \STR_PAD_RIGHT);
|
||||
$password = base64_encode(random_bytes(20));
|
||||
|
||||
$encryptMethod = ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256;
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile
|
||||
->addFromString('codes.csv', $contents)
|
||||
->setPassword($password, $encryptMethod)
|
||||
->addFromString('codes.csv', $contents, ZipCompressionMethod::DEFLATED)
|
||||
->setPassword($password, ZipEncryptionMethod::WINZIP_AES_256)
|
||||
->saveAsFile($this->outputFilename)
|
||||
->close()
|
||||
;
|
||||
@@ -453,6 +459,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($file);
|
||||
$zipFile->setReadPassword($password);
|
||||
$zipFile->setPassword($password);
|
||||
$zipFile->setEntryComment('contents.txt', 'comment'); // change entry, but not changed contents
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
|
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Test add remote files to zip archive.
|
||||
@@ -48,7 +49,6 @@ class ZipRemoteFileTest extends ZipTestCase
|
||||
|
||||
$fileName = 'remote-file-from-http-stream.md';
|
||||
$zipFile->addFromStream($fp, $fileName);
|
||||
|
||||
$zipFile->saveAsFile($outputZip);
|
||||
$zipFile->close();
|
||||
|
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipSlipVulnerabilityTest.
|
||||
@@ -15,7 +18,7 @@ namespace PhpZip;
|
||||
class ZipSlipVulnerabilityTest extends ZipTestCase
|
||||
{
|
||||
/**
|
||||
* @throws Exception\ZipException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testCreateSlipVulnerabilityFile()
|
||||
{
|
||||
@@ -27,7 +30,7 @@ class ZipSlipVulnerabilityTest extends ZipTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\ZipException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testUnpack()
|
||||
{
|
112
tests/ZipStreamOpenTest.php
Normal file
112
tests/ZipStreamOpenTest.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PhpZip\Exception\InvalidArgumentException;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipStreamOpenTest.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @medium
|
||||
*/
|
||||
class ZipStreamOpenTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideStreams
|
||||
*
|
||||
* @param resource $resource
|
||||
* @param string|null $exceptionClass
|
||||
* @param string|null $exceptionMessage
|
||||
*
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testOpenStream($resource, $exceptionClass = null, $exceptionMessage = null)
|
||||
{
|
||||
if ($resource === null) {
|
||||
static::markTestSkipped('skip null resource');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($exceptionClass !== null) {
|
||||
$this->setExpectedException(
|
||||
$exceptionClass,
|
||||
$exceptionMessage
|
||||
);
|
||||
}
|
||||
|
||||
static::assertInternalType('resource', $resource);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFromStream($resource);
|
||||
|
||||
static::assertTrue(fclose($resource));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|\Generator
|
||||
*/
|
||||
public function provideStreams()
|
||||
{
|
||||
return [
|
||||
'file' => yield [fopen(__DIR__ . '/resources/apk.zip', 'rb'), null, null],
|
||||
'directory' => yield [
|
||||
fopen(__DIR__, 'rb'),
|
||||
InvalidArgumentException::class,
|
||||
'Directory stream not supported',
|
||||
],
|
||||
'temp' => yield [$this->getTempResource('php://temp'), null, null],
|
||||
'memory' => yield [$this->getTempResource('php://memory'), null, null],
|
||||
'bz' => yield [
|
||||
$this->getBzResource(),
|
||||
InvalidArgumentException::class,
|
||||
'The stream wrapper type "Unknown" is not supported.',
|
||||
],
|
||||
'url' => yield [
|
||||
fopen('https://github.com/Ne-Lexa/php-zip/archive/master.zip', 'rb'),
|
||||
InvalidArgumentException::class,
|
||||
'The stream wrapper type "http" is not supported.',
|
||||
],
|
||||
'ftp' => yield [
|
||||
fopen('ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest.md5', 'rb'),
|
||||
InvalidArgumentException::class,
|
||||
'The stream wrapper type "ftp" is not supported.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function getTempResource($filename)
|
||||
{
|
||||
$fp = fopen(__DIR__ . '/resources/apk.zip', 'rb');
|
||||
$stream = fopen($filename, 'r+b');
|
||||
stream_copy_to_stream($fp, $stream);
|
||||
fclose($fp);
|
||||
rewind($stream);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource|null
|
||||
*/
|
||||
private function getBzResource()
|
||||
{
|
||||
if (!\extension_loaded('bz2')) {
|
||||
return null;
|
||||
}
|
||||
$stream = bzopen('php://temp', 'w');
|
||||
bzwrite($stream, 'some input here');
|
||||
|
||||
return $stream;
|
||||
}
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip;
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PhpZip\Model\EndOfCentralDirectory;
|
||||
use PhpZip\Constants\ZipConstants;
|
||||
use PhpZip\Util\FilesUtil;
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ abstract class ZipTestCase extends TestCase
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function existsProgram($program)
|
||||
protected static function existsProgram($program)
|
||||
{
|
||||
if (\DIRECTORY_SEPARATOR !== '\\') {
|
||||
exec('which ' . escapeshellarg($program), $output, $returnCode);
|
||||
@@ -132,7 +132,7 @@ abstract class ZipTestCase extends TestCase
|
||||
|
||||
static::assertContains('Empty zipfile', $output);
|
||||
}
|
||||
$actualEmptyZipData = pack('VVVVVv', EndOfCentralDirectory::END_OF_CD_SIG, 0, 0, 0, 0, 0);
|
||||
$actualEmptyZipData = pack('VVVVVv', ZipConstants::END_CD, 0, 0, 0, 0, 0);
|
||||
static::assertStringEqualsFile($filename, $actualEmptyZipData);
|
||||
}
|
||||
|
||||
@@ -158,4 +158,19 @@ abstract class ZipTestCase extends TestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function skipTestForRootUser()
|
||||
{
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
if (\extension_loaded('posix') && posix_getuid() === 0) {
|
||||
static::markTestSkipped('Skip the test for a user with root privileges');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user