From 8c0ee5bf194430e5c511d8a0d93f05bac7e8f27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:00:17 +0100 Subject: [PATCH] chore: cleanup tests folder --- .github/workflows/ci.yml | 4 +- .gitignore | 3 +- .travis.yml | 31 ------------ composer.json | 16 +++--- src/Count64.php | 19 ++------ src/Lib/Count64Base.php | 2 +- src/Lib/Count64_32.php | 2 +- src/Lib/Count64_64.php | 7 +-- src/ZipStreamer.php | 14 +++--- test/integration/Dockerfile | 19 -------- tests/.phpunit.result.cache | 1 + {test => tests}/Count64Test.php | 48 ++++++++++-------- {test/integration => tests}/UnpackTest.php | 24 +++++++-- {test => tests}/ZipComponents.php | 17 +++++-- {test => tests}/ZipStreamerTest.php | 57 ++++++++++++---------- {test => tests}/bootstrap.php | 0 {test => tests}/phpunit.xml | 4 +- 17 files changed, 125 insertions(+), 143 deletions(-) delete mode 100644 .travis.yml delete mode 100644 test/integration/Dockerfile create mode 100644 tests/.phpunit.result.cache rename {test => tests}/Count64Test.php (73%) rename {test/integration => tests}/UnpackTest.php (76%) rename {test => tests}/ZipComponents.php (98%) rename {test => tests}/ZipStreamerTest.php (91%) rename {test => tests}/bootstrap.php (100%) rename {test => tests}/phpunit.xml (66%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index daf8688..f4bc6b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] coverage: [ 'xdebug' ] # ZipStreamerTest depends on xdebug_get_headers => if coverage none/pcov then xdebug is disabled. steps: - name: Checkout @@ -83,7 +83,7 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: PHPUnit - run: vendor/bin/phpunit --verbose --configuration test/phpunit.xml + run: vendor/bin/phpunit --verbose --configuration tests/phpunit.xml # run: vendor/bin/phpunit --verbose --configuration tests/phpunit.xml --coverage-clover=coverage.xml diff --git a/.gitignore b/.gitignore index 5cde816..ede7f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /composer.lock /composer.phar -/test/.phpunit.result.cache +/tests/.phpunit.result.cache +/vendor \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1bd5181..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: php -dist: trusty -sudo: required - -services: - - docker - -env: - - PECL_HTTP_VERSION=3.1.1RC1 - -php: - - 7.2 - - 7.1 - - 7.0 - -before_install: - - docker build -t datawraith/p7zip test/integration - - composer install --dev - - sudo apt-get install unzip libgnutls-dev - - pecl channel-update pecl.php.net - - printf "\n\n\n" | pecl install pecl_http-$PECL_HTTP_VERSION - -script: - - vendor/bin/phpunit --configuration test/phpunit.xml - -matrix: - fast_finish: true - include: - - php: 5.6 - env: PECL_HTTP_VERSION=2.6.0 - diff --git a/composer.json b/composer.json index 41121d1..e5666bf 100644 --- a/composer.json +++ b/composer.json @@ -35,16 +35,13 @@ "role": "Contributor" } ], - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/DeepDiver1975/PHPZipStreamer" - } - ], "require": { - "php": ">=7.1" + "php": ">=7.1", + "ext-mbstring": "*" }, "require-dev": { + "ext-xdebug": "*", + "ext-zlib": "*", "phpunit/phpunit": "^7 || ^8" }, "suggest": { @@ -54,5 +51,10 @@ "psr-4": { "ZipStreamer\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } } } diff --git a/src/Count64.php b/src/Count64.php index ab58bbe..1101f0d 100644 --- a/src/Count64.php +++ b/src/Count64.php @@ -22,8 +22,9 @@ */ namespace ZipStreamer; -use \ZipStreamer\Lib\Count64_32; -use \ZipStreamer\Lib\Count64_64; +use ZipStreamer\Lib\Count64_32; +use ZipStreamer\Lib\Count64_64; +use ZipStreamer\Lib\Count64Base; const INT64_HIGH_MAP = 0xffffffff00000000; const INT64_LOW_MAP = 0x00000000ffffffff; @@ -43,16 +44,6 @@ function urShift($bits, $shift) { return ($bits >> $shift) & ~(1 << (8 * PHP_INT_SIZE - 1) >> ($shift - 1)); } -/** - * Convert binary data string to readable hex string - * - * @param string $data binary string - * @return string readable hex string - */ -function byte2hex($data) { - return unpack("h*", $data); -} - /** * Pack 1 byte data into binary string * @@ -149,8 +140,8 @@ abstract class Count64 { public static function construct($value = 0, $limit32Bit = False) { if (4 == PHP_INT_SIZE) { return new Count64_32($value, $limit32Bit); - } else { - return new Count64_64($value, $limit32Bit); } + + return new Count64_64($value, $limit32Bit); } } diff --git a/src/Lib/Count64Base.php b/src/Lib/Count64Base.php index 7ae5dcd..a97a047 100644 --- a/src/Lib/Count64Base.php +++ b/src/Lib/Count64Base.php @@ -25,7 +25,7 @@ abstract class Count64Base { protected $limit32Bit = False; - function __construct($value = 0, $limit32Bit = False) { + public function __construct($value = 0, $limit32Bit = False) { $this->limit32Bit = $limit32Bit; $this->set($value); } diff --git a/src/Lib/Count64_32.php b/src/Lib/Count64_32.php index e8c7ceb..8005774 100644 --- a/src/Lib/Count64_32.php +++ b/src/Lib/Count64_32.php @@ -42,7 +42,7 @@ public function set($value) { if (is_int($value)) { $this->loBytes = $value; $this->hiBytes = 0; - } else if (is_array($value) && 2 == sizeof($value)) { + } else if (is_array($value) && 2 == count($value)) { $this->loBytes = $value[0]; if ($this->limit32Bit && 0 !== $value[1]) { throw new \OverflowException(self::EXCEPTION_32BIT_OVERFLOW); diff --git a/src/Lib/Count64_64.php b/src/Lib/Count64_64.php index 1a31741..e27021a 100644 --- a/src/Lib/Count64_64.php +++ b/src/Lib/Count64_64.php @@ -22,8 +22,9 @@ */ namespace ZipStreamer\Lib; -use const \ZipStreamer\INT64_LOW_MAP; -use const \ZipStreamer\INT_MAX_32; +use function ZipStreamer\urShift; +use const ZipStreamer\INT64_LOW_MAP; +use const ZipStreamer\INT_MAX_32; class Count64_64 extends Count64Base { private $value; @@ -46,7 +47,7 @@ public function set($value) { throw new \OverFlowException(self::EXCEPTION_32BIT_OVERFLOW); } $this->value = $value; - } else if (is_array($value) && 2 == sizeof($value)) { + } else if (is_array($value) && 2 == count($value)) { if ($this->limit32Bit && 0 !== $value[1]) { throw new \OverFlowException(self::EXCEPTION_32BIT_OVERFLOW); } diff --git a/src/ZipStreamer.php b/src/ZipStreamer.php index 6cd1a97..464bfba 100644 --- a/src/ZipStreamer.php +++ b/src/ZipStreamer.php @@ -48,7 +48,7 @@ class ZipStreamer { private $extFileAttrFile; private $extFileAttrDir; - /** @var stream output stream zip file is written to */ + /** @var resource $outStream output stream zip file is written to */ private $outStream; /** @var boolean zip64 enabled */ private $zip64 = True; @@ -438,7 +438,7 @@ private function addDataDescriptor($dataLength, $gzLength, $dataCRC32) { private function buildZip64EndOfCentralDirectoryRecord($cdRecLength) { $versionToExtract = $this->getVersionToExtract(False); - $cdRecCount = sizeof($this->cdRec); + $cdRecCount = count($this->cdRec); return '' . pack32le(self::ZIP64_END_OF_CENTRAL_DIRECTORY) // zip64 end of central dir signature 4 bytes (0x06064b50) @@ -517,12 +517,12 @@ private function buildCentralDirectoryHeader($filePath, $timestamp, $gpFlags, private function buildEndOfCentralDirectoryRecord($cdRecLength) { if ($this->zip64) { $diskNumber = -1; - $cdRecCount = min(sizeof($this->cdRec), 0xffff); + $cdRecCount = min(count($this->cdRec), 0xffff); $cdRecLength = -1; $offset = -1; } else { $diskNumber = 0; - $cdRecCount = sizeof($this->cdRec); + $cdRecCount = count($this->cdRec); $offset = $this->offset->getLoBytes(); } //throw new \Exception(sprintf("zip64 %d diskno %d", $this->zip64, $diskNumber)); @@ -646,7 +646,7 @@ protected function __construct($level) { $class = self::PECL2_DEFLATE_STREAM_CLASS; } if (!class_exists($class)) { - new \Exception('unable to instantiate PECL deflate stream (requires pecl_http >= 0.10)'); + throw new \Exception('unable to instantiate PECL deflate stream (requires pecl_http >= 0.10)'); } $deflateFlags = constant($class . '::TYPE_RAW'); @@ -723,8 +723,8 @@ class GPFLAGS { // compression settings for deflate/deflate64 const DEFL_NORM = 0x0000; // normal compression (COMP1 and COMP2 not set) - const DEFL_MAX = COMP1; // maximum compression - const DEFL_FAST = COMP2; // fast compression + const DEFL_MAX = self::COMP1; // maximum compression + const DEFL_FAST = self::COMP2; // fast compression const DEFL_SFAST = 0x0006; // superfast compression (COMP1 and COMP2 set) } diff --git a/test/integration/Dockerfile b/test/integration/Dockerfile deleted file mode 100644 index 03ff843..0000000 --- a/test/integration/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM alpine:3.6 -MAINTAINER Johannes Holzfuß - -# This Dockerfile containerizes p7zip. -# -# You must run it using the correct UID/GID via the -u switch to `docker run` -# or the permissions will be wrong. -# -# Example usage -# docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd)":/data datawraith/p7zip a archive.7z file1 file2 file3 - -RUN apk --update add \ - p7zip \ - && rm -rf /var/cache/apk/* - -RUN mkdir /data -WORKDIR /data - -ENTRYPOINT ["7z"] diff --git a/tests/.phpunit.result.cache b/tests/.phpunit.result.cache new file mode 100644 index 0000000..a45aeef --- /dev/null +++ b/tests/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"Count64Test::testCount64SetFail with data set #0":6,"Count64Test::testCount64SetFail with data set #1":6,"Count64Test::testCount64SetFail with data set #2":6,"Count64Test::testCount64SetFail with data set #3":6,"Tests\\Count64Test::testPack16le with data set #0":4,"Tests\\Count64Test::testPack16le with data set #1":4,"Tests\\Count64Test::testPack16le with data set #2":4,"Tests\\Count64Test::testPack16le with data set #3":4,"Tests\\Count64Test::testPack16le with data set #4":4,"Tests\\Count64Test::testPack16le with data set #5":4,"Tests\\Count64Test::testPack16le with data set #6":4,"Tests\\Count64Test::testPack16le with data set #7":4,"Tests\\Count64Test::testPack32le with data set #0":4,"Tests\\Count64Test::testPack32le with data set #1":4,"Tests\\Count64Test::testPack32le with data set #2":4,"Tests\\Count64Test::testPack32le with data set #3":4,"Tests\\Count64Test::testPack32le with data set #4":4,"Tests\\Count64Test::testPack32le with data set #5":4,"Tests\\Count64Test::testPack32le with data set #6":4,"Tests\\Count64Test::testPack32le with data set #7":4,"Warning":6,"Tests\\Count64Test::testCount64ConstructFail with data set #0":3,"Tests\\Count64Test::testCount64ConstructFail with data set #1":3,"Tests\\Count64Test::testCount64ConstructFail with data set #2":3,"Tests\\Count64Test::testCount64ConstructFail with data set #3":3,"Tests\\Count64Test::testCount64SetFail with data set #0":3,"Tests\\Count64Test::testCount64SetFail with data set #1":3,"Tests\\Count64Test::testCount64SetFail with data set #2":3,"Tests\\Count64Test::testCount64SetFail with data set #3":3,"Tests\\Count64Test::testCount64Add with data set #0":4,"Tests\\Count64Test::testCount64Add with data set #1":4,"Tests\\Count64Test::testCount64Add with data set #2":4,"Tests\\Count64Test::testCount64Add with data set #3":4,"Tests\\Count64Test::testCount64Add with data set #4":4,"Tests\\Count64Test::testCount64Add with data set #5":4,"Tests\\UnpackTest::test7zip":4,"Tests\\UnpackTest::testUnzip":4,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #0":4,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #1":4,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #2":4,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #3":4,"Tests\\TestZipStreamer::testIssue29":4,"Tests\\Count64Test::testPack64le with data set #0":4,"Tests\\Count64Test::testPack64le with data set #1":4,"Tests\\Count64Test::testPack64le with data set #2":4,"Tests\\Count64Test::testPack64le with data set #3":4,"Tests\\Count64Test::testPack64le with data set #4":4,"Tests\\Count64Test::testPack64le with data set #5":4,"Tests\\TestZipStreamer::testZipfile with data set #0":4,"Tests\\TestZipStreamer::testZipfile with data set #1":4,"Tests\\TestZipStreamer::testZipfile with data set #2":4,"Tests\\TestZipStreamer::testZipfile with data set #3":4,"Tests\\TestZipStreamer::testZipfile with data set #4":4,"Tests\\TestZipStreamer::testZipfile with data set #5":4,"Tests\\TestZipStreamer::testZipfile with data set #6":4,"Tests\\TestZipStreamer::testZipfile with data set #7":4,"Tests\\TestZipStreamer::testZipfile with data set #8":4,"Tests\\TestZipStreamer::testZipfile with data set #9":4,"Tests\\TestZipStreamer::testZipfile with data set #10":4,"Tests\\TestZipStreamer::testZipfile with data set #11":4,"Tests\\TestZipStreamer::testZipfile with data set #12":4,"Tests\\TestZipStreamer::testZipfile with data set #13":4,"Tests\\TestZipStreamer::testZipfile with data set #14":4,"Tests\\TestZipStreamer::testZipfile with data set #15":4,"Tests\\TestZipStreamer::testZipfile with data set #16":4,"Tests\\TestZipStreamer::testZipfile with data set #17":4,"Tests\\TestZipStreamer::testZipfile with data set #18":4,"Tests\\TestZipStreamer::testZipfile with data set #19":4,"Tests\\TestZipStreamer::testZipfile with data set #20":4,"Tests\\TestZipStreamer::testZipfile with data set #21":4,"Tests\\TestZipStreamer::testZipfile with data set #22":4,"Tests\\TestZipStreamer::testZipfile with data set #23":4,"Tests\\TestZipStreamer::testZipfile with data set #24":4,"Tests\\TestZipStreamer::testZipfile with data set #25":4,"Tests\\TestZipStreamer::testZipfile with data set #26":4,"Tests\\TestZipStreamer::testZipfile with data set #27":4,"Tests\\TestZipStreamer::testZipfile with data set #28":4,"Tests\\TestZipStreamer::testZipfile with data set #29":4,"Tests\\TestZipStreamer::testZipfile with data set #30":4,"Tests\\TestZipStreamer::testZipfile with data set #31":4,"Tests\\TestZipStreamer::testZipfile with data set #32":4,"Tests\\TestZipStreamer::testZipfile with data set #33":4,"Tests\\TestZipStreamer::testZipfile with data set #34":4,"Tests\\TestZipStreamer::testZipfile with data set #35":4,"Tests\\TestZipStreamer::testZipfile with data set #36":4,"Tests\\TestZipStreamer::testZipfile with data set #37":4,"Tests\\TestZipStreamer::testZipfile with data set #38":4,"Tests\\TestZipStreamer::testZipfile with data set #39":4,"Tests\\Count64Test::testCount64Construct with data set #0":4,"Tests\\Count64Test::testCount64Construct with data set #1":4,"Tests\\Count64Test::testCount64Construct with data set #2":4,"Tests\\Count64Test::testCount64Construct with data set #3":4,"Tests\\Count64Test::testCount64Construct with data set #4":4,"Tests\\Count64Test::testCount64Construct with data set #5":4,"Tests\\Count64Test::testCount64Construct with data set #6":4,"Tests\\Count64Test::testCount64Construct with data set #7":4,"Tests\\Count64Test::testCount64Set with data set #0":4,"Tests\\Count64Test::testCount64Set with data set #1":4,"Tests\\Count64Test::testCount64Set with data set #2":4,"Tests\\Count64Test::testCount64Set with data set #3":4,"Tests\\Count64Test::testCount64Set with data set #4":4,"Tests\\Count64Test::testCount64Set with data set #5":4,"Tests\\Count64Test::testCount64Set with data set #6":4,"Tests\\Count64Test::testCount64Set with data set #7":4},"times":{"Count64Test::testPack16le with data set #0":0.001,"Count64Test::testPack16le with data set #1":0,"Count64Test::testPack16le with data set #2":0,"Count64Test::testPack16le with data set #3":0,"Count64Test::testPack16le with data set #4":0,"Count64Test::testPack16le with data set #5":0,"Count64Test::testPack16le with data set #6":0,"Count64Test::testPack16le with data set #7":0,"Count64Test::testPack32le with data set #0":0,"Count64Test::testPack32le with data set #1":0,"Count64Test::testPack32le with data set #2":0,"Count64Test::testPack32le with data set #3":0,"Count64Test::testPack32le with data set #4":0,"Count64Test::testPack32le with data set #5":0,"Count64Test::testPack32le with data set #6":0,"Count64Test::testPack32le with data set #7":0,"Count64Test::testPack64le with data set #0":0,"Count64Test::testPack64le with data set #1":0,"Count64Test::testPack64le with data set #2":0,"Count64Test::testPack64le with data set #3":0,"Count64Test::testPack64le with data set #4":0,"Count64Test::testPack64le with data set #5":0,"Count64Test::testCount64Construct with data set #0":0,"Count64Test::testCount64Construct with data set #1":0,"Count64Test::testCount64Construct with data set #2":0,"Count64Test::testCount64Construct with data set #3":0,"Count64Test::testCount64Construct with data set #4":0,"Count64Test::testCount64Construct with data set #5":0,"Count64Test::testCount64Construct with data set #6":0,"Count64Test::testCount64Construct with data set #7":0,"Count64Test::testCount64ConstructFail with data set #0":0,"Count64Test::testCount64ConstructFail with data set #1":0,"Count64Test::testCount64ConstructFail with data set #2":0,"Count64Test::testCount64ConstructFail with data set #3":0,"Count64Test::testCount64Set with data set #0":0,"Count64Test::testCount64Set with data set #1":0,"Count64Test::testCount64Set with data set #2":0,"Count64Test::testCount64Set with data set #3":0,"Count64Test::testCount64Set with data set #4":0,"Count64Test::testCount64Set with data set #5":0,"Count64Test::testCount64Set with data set #6":0,"Count64Test::testCount64Set with data set #7":0,"Count64Test::testCount64SetFail with data set #0":0.001,"Count64Test::testCount64SetFail with data set #1":0.001,"Count64Test::testCount64SetFail with data set #2":0.001,"Count64Test::testCount64SetFail with data set #3":0,"Count64Test::testCount64Add with data set #0":0,"Count64Test::testCount64Add with data set #1":0,"Count64Test::testCount64Add with data set #2":0,"Count64Test::testCount64Add with data set #3":0,"Count64Test::testCount64Add with data set #4":0,"Count64Test::testCount64Add with data set #5":0,"test\\UnpackTest::test7zip":0.005,"test\\UnpackTest::testUnzip":0.003,"ZipStreamer\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #0":0.003,"ZipStreamer\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #1":0.002,"ZipStreamer\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #2":0.002,"ZipStreamer\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #3":0.002,"ZipStreamer\\TestZipStreamer::testZipfile with data set #0":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #1":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #2":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #3":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #4":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #5":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #6":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #7":0.002,"ZipStreamer\\TestZipStreamer::testZipfile with data set #8":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #9":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #10":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #11":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #12":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #13":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #14":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #15":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #16":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #17":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #18":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #19":0.002,"ZipStreamer\\TestZipStreamer::testZipfile with data set #20":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #21":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #22":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #23":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #24":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #25":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #26":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #27":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #28":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #29":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #30":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #31":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #32":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #33":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #34":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #35":0.001,"ZipStreamer\\TestZipStreamer::testZipfile with data set #36":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #37":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #38":0,"ZipStreamer\\TestZipStreamer::testZipfile with data set #39":0.001,"ZipStreamer\\TestZipStreamer::testIssue29":0.005,"Tests\\Count64Test::testPack16le with data set #0":0.001,"Tests\\Count64Test::testPack16le with data set #1":0,"Tests\\Count64Test::testPack16le with data set #2":0,"Tests\\Count64Test::testPack16le with data set #3":0,"Tests\\Count64Test::testPack16le with data set #4":0,"Tests\\Count64Test::testPack16le with data set #5":0,"Tests\\Count64Test::testPack16le with data set #6":0,"Tests\\Count64Test::testPack16le with data set #7":0,"Tests\\Count64Test::testPack32le with data set #0":0,"Tests\\Count64Test::testPack32le with data set #1":0,"Tests\\Count64Test::testPack32le with data set #2":0,"Tests\\Count64Test::testPack32le with data set #3":0,"Tests\\Count64Test::testPack32le with data set #4":0,"Tests\\Count64Test::testPack32le with data set #5":0,"Tests\\Count64Test::testPack32le with data set #6":0,"Tests\\Count64Test::testPack32le with data set #7":0,"Warning":0.001,"Tests\\Count64Test::testCount64ConstructFail with data set #0":0.001,"Tests\\Count64Test::testCount64ConstructFail with data set #1":0,"Tests\\Count64Test::testCount64ConstructFail with data set #2":0,"Tests\\Count64Test::testCount64ConstructFail with data set #3":0,"Tests\\Count64Test::testCount64SetFail with data set #0":0,"Tests\\Count64Test::testCount64SetFail with data set #1":0,"Tests\\Count64Test::testCount64SetFail with data set #2":0,"Tests\\Count64Test::testCount64SetFail with data set #3":0,"Tests\\Count64Test::testCount64Add with data set #0":0,"Tests\\Count64Test::testCount64Add with data set #1":0,"Tests\\Count64Test::testCount64Add with data set #2":0,"Tests\\Count64Test::testCount64Add with data set #3":0,"Tests\\Count64Test::testCount64Add with data set #4":0,"Tests\\Count64Test::testCount64Add with data set #5":0,"Tests\\UnpackTest::test7zip":0.045,"Tests\\UnpackTest::testUnzip":0.031,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #0":0.004,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #1":0.004,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #2":0.004,"Tests\\TestZipStreamer::testSendHeadersOKWithRegularBrowser with data set #3":0.002,"Tests\\TestZipStreamer::testIssue29":0,"Tests\\Count64Test::testPack64le with data set #0":0,"Tests\\Count64Test::testPack64le with data set #1":0,"Tests\\Count64Test::testPack64le with data set #2":0,"Tests\\Count64Test::testPack64le with data set #3":0,"Tests\\Count64Test::testPack64le with data set #4":0,"Tests\\Count64Test::testPack64le with data set #5":0,"Tests\\TestZipStreamer::testZipfile with data set #0":0.001,"Tests\\TestZipStreamer::testZipfile with data set #1":0.001,"Tests\\TestZipStreamer::testZipfile with data set #2":0.001,"Tests\\TestZipStreamer::testZipfile with data set #3":0.002,"Tests\\TestZipStreamer::testZipfile with data set #4":0,"Tests\\TestZipStreamer::testZipfile with data set #5":0.001,"Tests\\TestZipStreamer::testZipfile with data set #6":0.001,"Tests\\TestZipStreamer::testZipfile with data set #7":0.002,"Tests\\TestZipStreamer::testZipfile with data set #8":0,"Tests\\TestZipStreamer::testZipfile with data set #9":0.001,"Tests\\TestZipStreamer::testZipfile with data set #10":0.001,"Tests\\TestZipStreamer::testZipfile with data set #11":0.001,"Tests\\TestZipStreamer::testZipfile with data set #12":0,"Tests\\TestZipStreamer::testZipfile with data set #13":0.001,"Tests\\TestZipStreamer::testZipfile with data set #14":0.001,"Tests\\TestZipStreamer::testZipfile with data set #15":0.002,"Tests\\TestZipStreamer::testZipfile with data set #16":0,"Tests\\TestZipStreamer::testZipfile with data set #17":0.001,"Tests\\TestZipStreamer::testZipfile with data set #18":0.001,"Tests\\TestZipStreamer::testZipfile with data set #19":0.002,"Tests\\TestZipStreamer::testZipfile with data set #20":0,"Tests\\TestZipStreamer::testZipfile with data set #21":0,"Tests\\TestZipStreamer::testZipfile with data set #22":0,"Tests\\TestZipStreamer::testZipfile with data set #23":0.001,"Tests\\TestZipStreamer::testZipfile with data set #24":0,"Tests\\TestZipStreamer::testZipfile with data set #25":0,"Tests\\TestZipStreamer::testZipfile with data set #26":0.001,"Tests\\TestZipStreamer::testZipfile with data set #27":0.001,"Tests\\TestZipStreamer::testZipfile with data set #28":0,"Tests\\TestZipStreamer::testZipfile with data set #29":0,"Tests\\TestZipStreamer::testZipfile with data set #30":0,"Tests\\TestZipStreamer::testZipfile with data set #31":0.001,"Tests\\TestZipStreamer::testZipfile with data set #32":0,"Tests\\TestZipStreamer::testZipfile with data set #33":0,"Tests\\TestZipStreamer::testZipfile with data set #34":0,"Tests\\TestZipStreamer::testZipfile with data set #35":0.001,"Tests\\TestZipStreamer::testZipfile with data set #36":0,"Tests\\TestZipStreamer::testZipfile with data set #37":0,"Tests\\TestZipStreamer::testZipfile with data set #38":0,"Tests\\TestZipStreamer::testZipfile with data set #39":0.001,"Tests\\Count64Test::testCount64Construct with data set #0":0,"Tests\\Count64Test::testCount64Construct with data set #1":0,"Tests\\Count64Test::testCount64Construct with data set #2":0,"Tests\\Count64Test::testCount64Construct with data set #3":0,"Tests\\Count64Test::testCount64Construct with data set #4":0,"Tests\\Count64Test::testCount64Construct with data set #5":0,"Tests\\Count64Test::testCount64Construct with data set #6":0,"Tests\\Count64Test::testCount64Construct with data set #7":0,"Tests\\Count64Test::testCount64Set with data set #0":0,"Tests\\Count64Test::testCount64Set with data set #1":0,"Tests\\Count64Test::testCount64Set with data set #2":0,"Tests\\Count64Test::testCount64Set with data set #3":0,"Tests\\Count64Test::testCount64Set with data set #4":0,"Tests\\Count64Test::testCount64Set with data set #5":0,"Tests\\Count64Test::testCount64Set with data set #6":0,"Tests\\Count64Test::testCount64Set with data set #7":0}} \ No newline at end of file diff --git a/test/Count64Test.php b/tests/Count64Test.php similarity index 73% rename from test/Count64Test.php rename to tests/Count64Test.php index be36e1b..6cf8b92 100644 --- a/test/Count64Test.php +++ b/tests/Count64Test.php @@ -6,9 +6,16 @@ * See COPYING for details. */ -use \ZipStreamer\Count64; +namespace Tests; -class TestPack extends \PHPUnit\Framework\TestCase +use PHPUnit\Framework\TestCase; +use ZipStreamer\Count64; +use ZipStreamer\Lib\Count64_64; +use function ZipStreamer\pack16le; +use function ZipStreamer\pack32le; +use function ZipStreamer\pack64le; + +class Count64Test extends TestCase { public function providerPack16leValues() { # input value, description @@ -28,7 +35,7 @@ public function providerPack16leValues() { * @dataProvider providerPack16leValues */ public function testPack16le($value, $description) { - $this->assertEquals(ZipStreamer\pack16le($value), pack('v', $value), $description); + $this->assertEquals(pack16le($value), pack('v', $value), $description); } public function providerPack32leValues() { @@ -49,18 +56,18 @@ public function providerPack32leValues() { * @dataProvider providerPack32leValues */ public function testPack32le($value, $description) { - $this->assertEquals(ZipStreamer\pack32le($value), pack('V', $value), $description); + $this->assertEquals(pack32le($value), pack('V', $value), $description); } public function providerPack64leValues() { # input value, expected high bytes, expected low bytes, description return array( array(0, 0, 0, "packing 0"), - array(ZipStreamer\Count64::construct(array(0xffffffff, 0x00000000)), 0xffffffff, 0x00000000, "packing pattern 0x00000000ffffffff"), - array(ZipStreamer\Count64::construct(array(0x00000000, 0xffffffff)), 0x00000000, 0xffffffff, "packing pattern 0xffffffff00000000"), - array(ZipStreamer\Count64::construct(array(0x0f0f0f0f, 0x0f0f0f0f)), 0x0f0f0f0f, 0x0f0f0f0f, "packing pattern 0x0f0f0f0f0f0f0f0f"), - array(ZipStreamer\Count64::construct(array(0xf0f0f0f0, 0xf0f0f0f0)), 0xf0f0f0f0, 0xf0f0f0f0, "packing pattern 0x00f0f0f0f0f0f0f0"), - array(ZipStreamer\Count64::construct(array(0xffffffff, 0xffffffff)), 0xffffffff, 0xffffffff, "packing maximum 64 bit value (0xffffffffffffffff)") + array(Count64::construct(array(0xffffffff, 0x00000000)), 0xffffffff, 0x00000000, "packing pattern 0x00000000ffffffff"), + array(Count64::construct(array(0x00000000, 0xffffffff)), 0x00000000, 0xffffffff, "packing pattern 0xffffffff00000000"), + array(Count64::construct(array(0x0f0f0f0f, 0x0f0f0f0f)), 0x0f0f0f0f, 0x0f0f0f0f, "packing pattern 0x0f0f0f0f0f0f0f0f"), + array(Count64::construct(array(0xf0f0f0f0, 0xf0f0f0f0)), 0xf0f0f0f0, 0xf0f0f0f0, "packing pattern 0x00f0f0f0f0f0f0f0"), + array(Count64::construct(array(0xffffffff, 0xffffffff)), 0xffffffff, 0xffffffff, "packing maximum 64 bit value (0xffffffffffffffff)") ); } @@ -68,7 +75,7 @@ public function providerPack64leValues() { * @dataProvider providerPack64leValues */ public function testPack64le($inVal, $cmpVal1, $cmpVal2, $description) { - $this->assertEquals(ZipStreamer\pack64le($inVal), pack('VV', $cmpVal1, $cmpVal2), $description); + $this->assertEquals(pack64le($inVal), pack('VV', $cmpVal1, $cmpVal2), $description); } public function providerGoodCount64InitializationValues() { @@ -81,7 +88,7 @@ public function providerGoodCount64InitializationValues() { array(0xffffffff, 0x00000000, array(0xffffffff, 0x00000000), "bit pattern array(0xffffffff, 0x00000000)"), array(0x0f0f0f0f, 0x0f0f0f0f, array(0x0f0f0f0f, 0x0f0f0f0f), "bit pattern array(0x0f0f0f0f, 0x0f0f0f0f)"), array(0xf0f0f0f0, 0xf0f0f0f0, array(0xf0f0f0f0, 0xf0f0f0f0), "bit pattern array(0xf0f0f0f0, 0xf0f0f0f0)"), - array(0x00000000, 0x00000000, ZipStreamer\Count64::construct(0), "Count64Base object (value 0)") + array(0x00000000, 0x00000000, Count64::construct(0), "Count64Base object (value 0)") ); } @@ -89,8 +96,8 @@ public function providerGoodCount64InitializationValues() { * @dataProvider providerGoodCount64InitializationValues */ public function testCount64Construct($loBytes, $hiBytes, $value, $description) { - $count64 = ZipStreamer\Count64::construct($value); - $this->assertInstanceOf('ZipStreamer\Count64Base', $count64, $description . ' (instanceof)'); + $count64 = Count64::construct($value); + $this->assertInstanceOf(Count64_64::class, $count64, $description . ' (instanceof)'); $this->assertEquals($loBytes, $count64->getLoBytes(), $description . " (loBytes)"); $this->assertEquals($hiBytes, $count64->getHiBytes(), $description . " (hiBytes)"); } @@ -107,29 +114,29 @@ public function providerBadCount64InitializationValues() { /** * @dataProvider providerBadCount64InitializationValues - * @expectedException InvalidArgumentException */ public function testCount64ConstructFail($badValue) { - $count64 = ZipStreamer\Count64::construct($badValue); + $this->expectException(\InvalidArgumentException::class); + $count64 = Count64::construct($badValue); } /** * @dataProvider providerGoodCount64InitializationValues */ public function testCount64Set($loBytes, $hiBytes, $value, $description) { - $count64 = ZipStreamer\Count64::construct(); + $count64 = Count64::construct(); $count64->set($value); - $this->assertInstanceOf('ZipStreamer\Count64Base', $count64, $description . ' (instanceof)'); + $this->assertInstanceOf(Count64_64::class, $count64, $description . ' (instanceof)'); $this->assertEquals($loBytes, $count64->getLoBytes(), $description . " (loBytes)"); $this->assertEquals($hiBytes, $count64->getHiBytes(), $description . " (hiBytes)"); } /** * @dataProvider providerBadCount64InitializationValues - * @expectedException InvalidArgumentException */ public function testCount64SetFail($badValue) { - $count64 = ZipStreamer\Count64::construct(); + $this->expectException(\InvalidArgumentException::class); + $count64 = Count64::construct(); $count64->set($badValue); } @@ -152,10 +159,9 @@ public function providerCount64AddValues() { * @dataProvider providerCount64AddValues */ public function testCount64Add($value, $add, $loBytes, $hiBytes, $description) { - $count64 = ZipStreamer\Count64::construct($value); + $count64 = Count64::construct($value); $count64->add($add); $this->assertEquals($loBytes, $count64->getLoBytes(), $description . " (loBytes)".sprintf("%x=%x", $loBytes, $count64->getLoBytes())); $this->assertEquals($hiBytes, $count64->getHiBytes(), $description . " (hiBytes)"); } } -?> diff --git a/test/integration/UnpackTest.php b/tests/UnpackTest.php similarity index 76% rename from test/integration/UnpackTest.php rename to tests/UnpackTest.php index 3618a38..6668e57 100644 --- a/test/integration/UnpackTest.php +++ b/tests/UnpackTest.php @@ -1,10 +1,16 @@ * */ - -class UnpackTest extends \PHPUnit\Framework\TestCase +class UnpackTest extends TestCase { /** @var false|string */ private $tmpfname; @@ -13,14 +19,17 @@ protected function setUp(): void { parent::setUp(); + $this->skipMissingCommand('7z'); + $this->skipMissingCommand('unzip'); + // create a zip file in tmp folder $this->tmpfname = tempnam('/tmp', 'FOO'); $outstream = fopen($this->tmpfname, 'wb'); - $zip = new ZipStreamer\ZipStreamer((array( + $zip = new ZipStreamer((array( 'outstream' => $outstream ))); - $stream = fopen(__DIR__ . '/../../README.md', 'rb'); + $stream = fopen(__DIR__ . '/../README.md', 'rb'); $zip->addFileFromStream($stream, 'README.test'); fclose($stream); $zip->finalize(); @@ -54,4 +63,11 @@ public function testUnzip(): void $this->assertEquals(' testing: README.test OK', $output[1]); $this->assertEquals('No errors detected in compressed data of ' . $this->tmpfname . '.', $output[2]); } + + private function skipMissingCommand($command) + { + if (shell_exec("which $command") === false) { + $this->markTestSkipped('command <$command> is missing'); + } + } } diff --git a/test/ZipComponents.php b/tests/ZipComponents.php similarity index 98% rename from test/ZipComponents.php rename to tests/ZipComponents.php index ac197d6..ee5f1d6 100644 --- a/test/ZipComponents.php +++ b/tests/ZipComponents.php @@ -6,7 +6,17 @@ * This file is licensed under the GNU GPL version 3 or later. * See COPYING for details. */ -namespace ZipStreamer; +namespace Tests; + +use PHPUnit\Framework\Assert; +use ZipStreamer\COMPR; +use ZipStreamer\Count64; +use ZipStreamer\GPFLAGS; +use function ZipStreamer\pack16le; +use function ZipStreamer\pack32le; +use function ZipStreamer\unpack16le; +use function ZipStreamer\unpack32le; +use function ZipStreamer\unpack64le; /** * @codeCoverageIgnore @@ -63,7 +73,7 @@ protected static function __constructFromString($str, $pos, $size = -1) { try { $eocdrec->readFromString($str, $pos, $size); } catch (Exception $e) { - $this->fail("error parsing end of central directory record"); + Assert::fail("error parsing end of central directory record"); } return $eocdrec; @@ -468,7 +478,7 @@ public function readFromString($str, $pos, $size = -1) { } } if (GPFLAGS::ADD & $this->lfh->gpFlags) { - if (is_null($this->lfh->z64Ext)) { + if ($this->lfh->z64Ext === null) { $ddLength = 16; } else { $ddLength = 24; @@ -611,4 +621,3 @@ public function readFromString($str, $pos, $size = -1) { $this->end = $pos - 1; } } -?> diff --git a/test/ZipStreamerTest.php b/tests/ZipStreamerTest.php similarity index 91% rename from test/ZipStreamerTest.php rename to tests/ZipStreamerTest.php index 5dac783..c0e9755 100644 --- a/test/ZipStreamerTest.php +++ b/tests/ZipStreamerTest.php @@ -6,7 +6,14 @@ * This file is licensed under the GNU GPL version 3 or later. * See COPYING for details. */ -namespace ZipStreamer; +namespace Tests; + +use ZipStreamer\COMPR; +use ZipStreamer\Count64; +use ZipStreamer\GPFLAGS; +use ZipStreamer\ZipStreamer; +use function ZipStreamer\pack16le; +use function ZipStreamer\pack32le; require_once __DIR__ . "/ZipComponents.php"; @@ -64,17 +71,17 @@ protected static function getVersionToExtract($zip64, $isDir) { } protected function assertOutputEqualsFile($filename) { - $this->assertEquals(file_get_contents($filename), $this->getOutput()); + $this->assertStringEqualsFile($filename, $this->getOutput()); } protected function assertContainsOneMatch($pattern, $input) { $results = preg_grep($pattern, $input); - $this->assertEquals(1, sizeof($results)); + $this->assertCount(1, $results); } protected function assertOutputZipfileOK($files, $options) { - if (0 < sizeof($files)) { // php5.3 does not combine empty arrays - $files = array_combine(array_map(function ($element) { + if (0 < count($files)) { // php5.3 does not combine empty arrays + $files = array_combine(array_map(static function ($element) { return $element->filename; }, $files), $files); } @@ -87,8 +94,8 @@ protected function assertOutputZipfileOK($files, $options) { $eocdrec->assertValues(array( "numberDisk" => 0xffff, "numberDiskStartCD" => 0xffff, - "numberEntriesDisk" => sizeof($files), - "numberEntriesCD" => sizeof($files), + "numberEntriesDisk" => count($files), + "numberEntriesCD" => count($files), "size" => 0xffffffff, "offsetStart" => 0xffffffff, "lengthComment" => 0, @@ -110,11 +117,11 @@ protected function assertOutputZipfileOK($files, $options) { $z64eocdrec->assertValues(array( "size" => Count64::construct(44), "madeByVersion" => pack16le(self::ATTR_MADE_BY_VERSION), - "versionToExtract" => pack16le($this->getVersionToExtract($options['zip64'], False)), + "versionToExtract" => pack16le(self::getVersionToExtract($options['zip64'], False)), "numberDisk" => 0, "numberDiskStartCDR" => 0, - "numberEntriesDisk" => Count64::construct(sizeof($files)), - "numberEntriesCD" => Count64::construct(sizeof($files)) + "numberEntriesDisk" => Count64::construct(count($files)), + "numberEntriesCD" => Count64::construct(count($files)) )); $sizeCD = $z64eocdrec->sizeCD->getLoBytes(); $offsetCD = $z64eocdrec->offsetStart->getLoBytes(); @@ -123,8 +130,8 @@ protected function assertOutputZipfileOK($files, $options) { $eocdrec->assertValues(array( "numberDisk" => 0, "numberDiskStartCD" => 0, - "numberEntriesDisk" => sizeof($files), - "numberEntriesCD" => sizeof($files), + "numberEntriesDisk" => count($files), + "numberEntriesCD" => count($files), "lengthComment" => 0, "comment" => '' )); @@ -146,7 +153,7 @@ protected function assertOutputZipfileOK($files, $options) { $this->assertArrayHasKey($filename, $files, "CDH entry has valid name"); $cdhead->assertValues(array( "madeByVersion" => pack16le(self::ATTR_MADE_BY_VERSION), - "versionToExtract" => pack16le($this->getVersionToExtract($options['zip64'], File::DIR == $files[$filename]->type)), + "versionToExtract" => pack16le(self::getVersionToExtract($options['zip64'], File::DIR == $files[$filename]->type)), "gpFlags" => (File::FILE == $files[$filename]->type ? pack16le(GPFLAGS::ADD) : pack16le(GPFLAGS::NONE)), "gzMethod" => (File::FILE == $files[$filename]->type ? pack16le($options['compress']) : pack16le(COMPR::STORE)), "dosTime" => pack32le(ZipStreamer::getDosTime($files[$filename]->date)), @@ -176,9 +183,9 @@ protected function assertOutputZipfileOK($files, $options) { )); } } - if (0 < sizeof($files)) { + if (0 < count($files)) { $this->assertEquals($cdhead->end + 1, $beginFollowingRecord, "CDH directly before following record"); - $this->assertEquals(sizeof($files), sizeof($cdheaders), "CDH has correct number of entries"); + $this->assertSameSize($files, $cdheaders, "CDH has correct number of entries"); $this->assertEquals($sizeCD, $beginFollowingRecord - $offsetCD, "CDH has correct size"); } else { $this->assertNull($cdhead); @@ -222,7 +229,7 @@ protected function assertOutputZipfileOK($files, $options) { )); } $file->lfh->assertValues(array( - "versionToExtract" => pack16le($this->getVersionToExtract($options['zip64'], File::DIR == $files[$filename]->type)), + "versionToExtract" => pack16le(self::getVersionToExtract($options['zip64'], File::DIR == $files[$filename]->type)), "gpFlags" => (File::FILE == $files[$filename]->type ? GPFLAGS::ADD : GPFLAGS::NONE), "gzMethod" => (File::FILE == $files[$filename]->type ? $options['compress'] : COMPR::STORE), "dosTime" => pack32le(ZipStreamer::getDosTime($files[$filename]->date)), @@ -234,7 +241,7 @@ protected function assertOutputZipfileOK($files, $options) { $endLastFile = $file->end; $first = False; } - if (0 < sizeof($files)) { + if (0 < count($files)) { $this->assertEquals($offsetCD, $endLastFile + 1, "last file directly before CDH"); } else { $this->assertEquals(0, $beginFollowingRecord, "empty zip file, CD records at beginning of file"); @@ -371,11 +378,11 @@ public function providerZipfileOK() { 'level' => $level[0] ); $description = $fileSet[1] . ' (options = array(zip64=' . $zip64[1] . ', compress=' . $compress[1] . ', level=' . $level[1] . '))'; - array_push($data, array( - $options, - $fileSet[0], - $description - )); + $data[] = array( + $options, + $fileSet[0], + $description + ); } } } @@ -415,8 +422,8 @@ public function testIssue29() { $stream = fopen('php://memory', 'r+'); $zip->addFileFromStream($stream, "test.bin"); fclose($stream); - $zip->finalize(); + $ret = $zip->finalize(); + self::assertTrue($ret); } -} -?> +} diff --git a/test/bootstrap.php b/tests/bootstrap.php similarity index 100% rename from test/bootstrap.php rename to tests/bootstrap.php diff --git a/test/phpunit.xml b/tests/phpunit.xml similarity index 66% rename from test/phpunit.xml rename to tests/phpunit.xml index eec7c74..9e2fca4 100644 --- a/test/phpunit.xml +++ b/tests/phpunit.xml @@ -7,8 +7,6 @@ bootstrap="bootstrap.php" > - ZipStreamerTest.php - lib - integration + .