Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup tests folder #17

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/composer.lock
/composer.phar
/test/.phpunit.result.cache
/tests/.phpunit.result.cache
/vendor
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -54,5 +51,10 @@
"psr-4": {
"ZipStreamer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
19 changes: 5 additions & 14 deletions src/Count64.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Lib/Count64Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Count64_32.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/Lib/Count64_64.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/ZipStreamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)
}

19 changes: 0 additions & 19 deletions test/integration/Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions tests/.phpunit.result.cache

Large diffs are not rendered by default.

48 changes: 27 additions & 21 deletions test/Count64Test.php → tests/Count64Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -49,26 +56,26 @@ 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)")
);
}

/**
* @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() {
Expand All @@ -81,16 +88,16 @@ 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)")
);
}

/**
* @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)");
}
Expand All @@ -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);
}

Expand All @@ -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)");
}
}
?>
Loading
Loading