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

php8 support

This commit is contained in:
Ne-Lexa
2021-02-22 13:12:01 +03:00
parent 44c2041f62
commit a65fe4579b
118 changed files with 4060 additions and 6568 deletions

View File

@@ -1,6 +1,13 @@
<?php
/** @noinspection PhpUndefinedMethodInspection */
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
@@ -8,32 +15,22 @@ use PHPUnit\Framework\TestCase;
use PhpZip\Exception\ZipException;
use PhpZip\Model\Extra\Fields\AbstractUnicodeExtraField;
/**
* Class AbstractUnicodeExtraFieldTest.
*/
abstract class AbstractUnicodeExtraFieldTest extends TestCase
{
/**
* @return string|AbstractUnicodeExtraField
*
* @psalm-var class-string<\PhpZip\Model\Extra\Fields\AbstractUnicodeExtraField>
* @psalm-var class-string<AbstractUnicodeExtraField>
*/
abstract protected function getUnicodeExtraFieldClassName();
/**
* @dataProvider provideExtraField
*
* @param int $crc32
* @param string $unicodePath
* @param string $originalPath
* @param string $binaryData
*
* @throws ZipException
*/
public function testExtraField($crc32, $unicodePath, $originalPath, $binaryData)
public function testExtraField(int $crc32, string $unicodePath, string $originalPath, string $binaryData): void
{
$crc32 = (int) $crc32; // for php 32-bit
$className = $this->getUnicodeExtraFieldClassName();
/** @var AbstractUnicodeExtraField $extraField */
@@ -48,12 +45,9 @@ abstract class AbstractUnicodeExtraFieldTest extends TestCase
static::assertEquals($className::unpackCentralDirData($binaryData), $extraField);
}
/**
* @return array
*/
abstract public function provideExtraField();
abstract public function provideExtraField(): array;
public function testSetter()
public function testSetter(): void
{
$className = $this->getUnicodeExtraFieldClassName();
$entryName = '11111';
@@ -74,12 +68,10 @@ abstract class AbstractUnicodeExtraFieldTest extends TestCase
/**
* @throws ZipException
*/
public function testUnicodeErrorParse()
public function testUnicodeErrorParse(): void
{
$this->expectException(
ZipException::class,
'Unicode path extra data must have at least 5 bytes.'
);
$this->expectException(ZipException::class);
$this->expectExceptionMessage('Unicode path extra data must have at least 5 bytes.');
$className = $this->getUnicodeExtraFieldClassName();
$className::unpackLocalFileData('');
@@ -88,12 +80,10 @@ abstract class AbstractUnicodeExtraFieldTest extends TestCase
/**
* @throws ZipException
*/
public function testUnknownVersionParse()
public function testUnknownVersionParse(): void
{
$this->expectException(
ZipException::class,
'Unsupported version [2] for Unicode path extra data.'
);
$this->expectException(ZipException::class);
$this->expectExceptionMessage('Unsupported version [2] for Unicode path extra data.');
$className = $this->getUnicodeExtraFieldClassName();
$className::unpackLocalFileData("\x02\x04a\xD28\xC3\xA4\\\xC3\xBC.txt");

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -16,19 +25,14 @@ final class ApkAlignmentExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $multiple
* @param int $padding
* @param string $binaryData
* @param string $toString
*
* @throws ZipException
*/
public function testExtraField(
$multiple,
$padding,
$binaryData,
$toString
) {
int $multiple,
int $padding,
string $binaryData,
string $toString
): void {
$extraField = new ApkAlignmentExtraField($multiple, $padding);
self::assertSame($extraField->getHeaderId(), ApkAlignmentExtraField::HEADER_ID);
self::assertSame($extraField->getMultiple(), $multiple);
@@ -43,10 +47,7 @@ final class ApkAlignmentExtraFieldTest extends TestCase
self::assertSame((string) $extraField, $toString);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -82,7 +83,7 @@ final class ApkAlignmentExtraFieldTest extends TestCase
];
}
public function testSetter()
public function testSetter(): void
{
$extraField = new ApkAlignmentExtraField(ApkAlignmentExtraField::ALIGNMENT_BYTES, 3);
$extraField->setMultiple(ApkAlignmentExtraField::COMMON_PAGE_ALIGNMENT_BYTES);
@@ -94,12 +95,10 @@ final class ApkAlignmentExtraFieldTest extends TestCase
/**
* @throws ZipException
*/
public function testInvalidParse()
public function testInvalidParse(): void
{
$this->expectException(
ZipException::class,
'Minimum 6 bytes of the extensible data block/field used for alignment of uncompressed entries.'
);
$this->expectException(ZipException::class);
$this->expectExceptionMessage('Minimum 6 bytes of the extensible data block/field used for alignment of uncompressed entries.');
ApkAlignmentExtraField::unpackLocalFileData("\x04");
}

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -17,15 +26,9 @@ final class AsiExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $mode
* @param int $uid
* @param int $gid
* @param string $link
* @param string $binaryData
*
* @throws ZipException
*/
public function testExtraField($mode, $uid, $gid, $link, $binaryData)
public function testExtraField(int $mode, int $uid, int $gid, string $link, string $binaryData): void
{
$asiExtraField = new AsiExtraField($mode, $uid, $gid, $link);
self::assertSame($asiExtraField->getHeaderId(), AsiExtraField::HEADER_ID);
@@ -42,10 +45,7 @@ final class AsiExtraFieldTest extends TestCase
self::assertEquals(AsiExtraField::unpackCentralDirData($binaryData), $asiExtraField);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -65,7 +65,7 @@ final class AsiExtraFieldTest extends TestCase
];
}
public function testSetter()
public function testSetter(): void
{
$extraField = new AsiExtraField(0777);
$extraField->setMode(0100666);
@@ -89,12 +89,10 @@ final class AsiExtraFieldTest extends TestCase
/**
* @throws Crc32Exception
*/
public function testInvalidParse()
public function testInvalidParse(): void
{
$this->expectException(
Crc32Exception::class,
'Asi Unix Extra Filed Data (expected CRC32 value'
);
$this->expectException(Crc32Exception::class);
$this->expectExceptionMessage('Asi Unix Extra Filed Data (expected CRC32 value');
AsiExtraField::unpackLocalFileData("\x01\x06\\\xF6\xEDA\x00\x00\x00\x00\xE8\x03\xE8\x03");
}

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -17,23 +26,20 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $flags
* @param int|null $modifyTime
* @param int|null $accessTime
* @param int|null $createTime
* @param string $localData
* @param string $cdData
*
* @noinspection PhpTooManyParametersInspection
*
* @param ?int $modifyTime
* @param ?int $accessTime
* @param ?int $createTime
*/
public function testExtraField(
$flags,
$modifyTime,
$accessTime,
$createTime,
$localData,
$cdData
) {
int $flags,
?int $modifyTime,
?int $accessTime,
?int $createTime,
string $localData,
string $cdData
): void {
$localExtraField = new ExtendedTimestampExtraField($flags, $modifyTime, $accessTime, $createTime);
self::assertSame($localExtraField->getHeaderId(), ExtendedTimestampExtraField::HEADER_ID);
self::assertSame($localExtraField->getFlags(), $flags);
@@ -59,16 +65,13 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
self::assertSame($localExtraField->packCentralDirData(), $cdData);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
ExtendedTimestampExtraField::MODIFY_TIME_BIT |
ExtendedTimestampExtraField::ACCESS_TIME_BIT |
ExtendedTimestampExtraField::CREATE_TIME_BIT,
ExtendedTimestampExtraField::MODIFY_TIME_BIT
| ExtendedTimestampExtraField::ACCESS_TIME_BIT
| ExtendedTimestampExtraField::CREATE_TIME_BIT,
911512006,
911430000,
893709400,
@@ -76,8 +79,8 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
"\x07\xC6\x91T6",
],
[
ExtendedTimestampExtraField::MODIFY_TIME_BIT |
ExtendedTimestampExtraField::ACCESS_TIME_BIT,
ExtendedTimestampExtraField::MODIFY_TIME_BIT
| ExtendedTimestampExtraField::ACCESS_TIME_BIT,
1492955702,
1492955638,
null,
@@ -98,7 +101,7 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
/**
* @throws \Exception
*/
public function testSetter()
public function testSetter(): void
{
$mtime = time();
$atime = null;
@@ -115,8 +118,8 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
$field->setAccessTime($atime);
self::assertSame(
$field->getFlags(),
ExtendedTimestampExtraField::MODIFY_TIME_BIT |
ExtendedTimestampExtraField::ACCESS_TIME_BIT
ExtendedTimestampExtraField::MODIFY_TIME_BIT
| ExtendedTimestampExtraField::ACCESS_TIME_BIT
);
self::assertSame($field->getModifyTime(), $mtime);
self::assertSame($field->getAccessTime(), $atime);
@@ -127,9 +130,9 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
$field->setCreateTime($ctime);
self::assertSame(
$field->getFlags(),
ExtendedTimestampExtraField::MODIFY_TIME_BIT |
ExtendedTimestampExtraField::ACCESS_TIME_BIT |
ExtendedTimestampExtraField::CREATE_TIME_BIT
ExtendedTimestampExtraField::MODIFY_TIME_BIT
| ExtendedTimestampExtraField::ACCESS_TIME_BIT
| ExtendedTimestampExtraField::CREATE_TIME_BIT
);
self::assertSame($field->getModifyTime(), $mtime);
self::assertSame($field->getAccessTime(), $atime);
@@ -141,8 +144,8 @@ final class ExtendedTimestampExtraFieldTest extends TestCase
self::assertNull($field->getCreateDateTime());
self::assertSame(
$field->getFlags(),
ExtendedTimestampExtraField::MODIFY_TIME_BIT |
ExtendedTimestampExtraField::ACCESS_TIME_BIT
ExtendedTimestampExtraField::MODIFY_TIME_BIT
| ExtendedTimestampExtraField::ACCESS_TIME_BIT
);
$field->setAccessTime(null);

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -18,7 +27,7 @@ final class JarMarkerExtraFieldTest extends TestCase
/**
* @throws ZipException
*/
public function testExtraField()
public function testExtraField(): void
{
$jarField = new JarMarkerExtraField();
self::assertSame('', $jarField->packLocalFileData());
@@ -30,12 +39,10 @@ final class JarMarkerExtraFieldTest extends TestCase
/**
* @throws ZipException
*/
public function testInvalidUnpackLocalData()
public function testInvalidUnpackLocalData(): void
{
$this->expectException(
ZipException::class,
"JarMarker doesn't expect any data"
);
$this->expectException(ZipException::class);
$this->expectExceptionMessage("JarMarker doesn't expect any data");
JarMarkerExtraField::unpackLocalFileData("\x02\x00\00");
}
@@ -43,12 +50,10 @@ final class JarMarkerExtraFieldTest extends TestCase
/**
* @throws ZipException
*/
public function testInvalidUnpackCdData()
public function testInvalidUnpackCdData(): void
{
$this->expectException(
ZipException::class,
"JarMarker doesn't expect any data"
);
$this->expectException(ZipException::class);
$this->expectExceptionMessage("JarMarker doesn't expect any data");
JarMarkerExtraField::unpackCentralDirData("\x02\x00\00");
}

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -18,14 +27,9 @@ final class NewUnixExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $version
* @param int $uid
* @param int $gid
* @param string $binaryData
*
* @throws ZipException
*/
public function testExtraField($version, $uid, $gid, $binaryData)
public function testExtraField(int $version, int $uid, int $gid, string $binaryData): void
{
$extraField = new NewUnixExtraField($version, $uid, $gid);
self::assertSame($extraField->getHeaderId(), NewUnixExtraField::HEADER_ID);
@@ -40,10 +44,7 @@ final class NewUnixExtraFieldTest extends TestCase
self::assertSame($extraField->packCentralDirData(), $binaryData);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -79,7 +80,7 @@ final class NewUnixExtraFieldTest extends TestCase
];
}
public function testSetter()
public function testSetter(): void
{
$extraField = new NewUnixExtraField(1, 1000, 1000);
self::assertSame(1, $extraField->getVersion());

View File

@@ -1,13 +1,20 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
use PhpZip\Model\Extra\Fields\NtfsExtraField;
/**
* Class NtfsExtraFieldTest.
*
* @internal
*
* @small
@@ -24,27 +31,19 @@ final class NtfsExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $modifyNtfsTime
* @param int $accessNtfsTime
* @param int $createNtfsTime
* @param float $modifyTimestamp
* @param float $accessTimestamp
* @param float $createTimestamp
* @param string $binaryData
*
* @throws \Exception
*
* @noinspection PhpTooManyParametersInspection
*/
public function testExtraField(
$modifyNtfsTime,
$accessNtfsTime,
$createNtfsTime,
$modifyTimestamp,
$accessTimestamp,
$createTimestamp,
$binaryData
) {
int $modifyNtfsTime,
int $accessNtfsTime,
int $createNtfsTime,
float $modifyTimestamp,
float $accessTimestamp,
float $createTimestamp,
string $binaryData
): void {
$extraField = new NtfsExtraField($modifyNtfsTime, $accessNtfsTime, $createNtfsTime);
self::assertSame($extraField->getHeaderId(), NtfsExtraField::HEADER_ID);
@@ -64,15 +63,24 @@ final class NtfsExtraFieldTest extends TestCase
$extraField->getCreateDateTime()
);
self::assertEqualsIntegerWithDelta($extraFieldFromDateTime->getModifyNtfsTime(), $extraField->getModifyNtfsTime(), 100);
self::assertEqualsIntegerWithDelta($extraFieldFromDateTime->getAccessNtfsTime(), $extraField->getAccessNtfsTime(), 100);
self::assertEqualsIntegerWithDelta($extraFieldFromDateTime->getCreateNtfsTime(), $extraField->getCreateNtfsTime(), 100);
self::assertEqualsIntegerWithDelta(
$extraFieldFromDateTime->getModifyNtfsTime(),
$extraField->getModifyNtfsTime(),
100
);
self::assertEqualsIntegerWithDelta(
$extraFieldFromDateTime->getAccessNtfsTime(),
$extraField->getAccessNtfsTime(),
100
);
self::assertEqualsIntegerWithDelta(
$extraFieldFromDateTime->getCreateNtfsTime(),
$extraField->getCreateNtfsTime(),
100
);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -105,18 +113,12 @@ final class NtfsExtraFieldTest extends TestCase
];
}
/**
* @param int $expected
* @param int $actual
* @param int $delta
* @param string $message
*/
private static function assertEqualsIntegerWithDelta(
$expected,
$actual,
$delta,
$message = ''
) {
int $expected,
int $actual,
int $delta,
string $message = ''
): void {
self::assertSame(
self::roundInt($expected, $delta),
self::roundInt($actual, $delta),
@@ -124,13 +126,7 @@ final class NtfsExtraFieldTest extends TestCase
);
}
/**
* @param int $number
* @param int $delta
*
* @return int
*/
private static function roundInt($number, $delta)
private static function roundInt(int $number, int $delta): int
{
return (int) (floor($number / $delta) * $delta);
}
@@ -138,27 +134,19 @@ final class NtfsExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $mtimeNtfs
* @param int $atimeNtfs
* @param int $ctimeNtfs
* @param float $mtimeTimestamp
* @param float $atimeTimestamp
* @param float $ctimeTimestamp
*
* @noinspection PhpTooManyParametersInspection
* @noinspection PhpUnitDeprecationsInspection
*/
public function testConverter(
$mtimeNtfs,
$atimeNtfs,
$ctimeNtfs,
$mtimeTimestamp,
$atimeTimestamp,
$ctimeTimestamp
) {
self::assertEquals(NtfsExtraField::ntfsTimeToTimestamp($mtimeNtfs), $mtimeTimestamp, '', 0.00001);
self::assertEquals(NtfsExtraField::ntfsTimeToTimestamp($atimeNtfs), $atimeTimestamp, '', 0.00001);
self::assertEquals(NtfsExtraField::ntfsTimeToTimestamp($ctimeNtfs), $ctimeTimestamp, '', 0.00001);
int $mtimeNtfs,
int $atimeNtfs,
int $ctimeNtfs,
float $mtimeTimestamp,
float $atimeTimestamp,
float $ctimeTimestamp
): void {
self::assertEqualsWithDelta(NtfsExtraField::ntfsTimeToTimestamp($mtimeNtfs), $mtimeTimestamp, 0.00001);
self::assertEqualsWithDelta(NtfsExtraField::ntfsTimeToTimestamp($atimeNtfs), $atimeTimestamp, 0.00001);
self::assertEqualsWithDelta(NtfsExtraField::ntfsTimeToTimestamp($ctimeNtfs), $ctimeTimestamp, 0.00001);
self::assertEqualsIntegerWithDelta(NtfsExtraField::timestampToNtfsTime($mtimeTimestamp), $mtimeNtfs, 10);
self::assertEqualsIntegerWithDelta(NtfsExtraField::timestampToNtfsTime($atimeTimestamp), $atimeNtfs, 10);
@@ -168,7 +156,7 @@ final class NtfsExtraFieldTest extends TestCase
/**
* @throws \Exception
*/
public function testSetter()
public function testSetter(): void
{
$timeZone = new \DateTimeZone('UTC');
$initDateTime = new \DateTimeImmutable('-1 min', $timeZone);

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -17,25 +26,23 @@ final class OldUnixExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int|null $accessTime
* @param int|null $modifyTime
* @param int|null $uid
* @param int|null $gid
* @param string $localBinaryData
* @param string $cdBinaryData
*
* @noinspection PhpTooManyParametersInspection
*
* @param ?int $accessTime
* @param ?int $modifyTime
* @param ?int $uid
* @param ?int $gid
*
* @throws \Exception
*/
public function testExtraField(
$accessTime,
$modifyTime,
$uid,
$gid,
$localBinaryData,
$cdBinaryData
) {
?int $accessTime,
?int $modifyTime,
?int $uid,
?int $gid,
string $localBinaryData,
string $cdBinaryData
): void {
$extraField = new OldUnixExtraField($accessTime, $modifyTime, $uid, $gid);
self::assertSame($extraField->getHeaderId(), OldUnixExtraField::HEADER_ID);
@@ -89,10 +96,7 @@ final class OldUnixExtraFieldTest extends TestCase
self::assertSame($extraField->packCentralDirData(), $cdBinaryData);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -130,7 +134,7 @@ final class OldUnixExtraFieldTest extends TestCase
];
}
public function testSetter()
public function testSetter(): void
{
$extraField = new OldUnixExtraField(null, null, null, null);

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PhpZip\Model\Extra\Fields\UnicodeCommentExtraField;
@@ -19,10 +28,7 @@ final class UnicodeCommentExtraFieldTest extends AbstractUnicodeExtraFieldTest
return UnicodeCommentExtraField::class;
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PhpZip\Model\Extra\Fields\UnicodePathExtraField;
@@ -21,10 +30,7 @@ final class UnicodePathExtraFieldTest extends AbstractUnicodeExtraFieldTest
return UnicodePathExtraField::class;
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -15,7 +24,7 @@ use PhpZip\Model\Extra\Fields\UnrecognizedExtraField;
*/
final class UnrecognizedExtraFieldTest extends TestCase
{
public function testExtraField()
public function testExtraField(): void
{
$headerId = 0xF00D;
$binaryData = "\x01\x02\x03\x04\x05";
@@ -35,22 +44,18 @@ final class UnrecognizedExtraFieldTest extends TestCase
self::assertSame($unrecognizedExtraField->packCentralDirData(), $newBinaryData);
}
public function testUnpackLocalData()
public function testUnpackLocalData(): void
{
$this->expectException(
RuntimeException::class,
'Unsupport parse'
);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Unsupport parse');
UnrecognizedExtraField::unpackLocalFileData("\x01\x02");
}
public function testUnpackCentralDirData()
public function testUnpackCentralDirData(): void
{
$this->expectException(
RuntimeException::class,
'Unsupport parse'
);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Unsupport parse');
UnrecognizedExtraField::unpackCentralDirData("\x01\x02");
}

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -20,22 +29,16 @@ final class WinZipAesExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int $vendorVersion
* @param int $keyStrength
* @param int $compressionMethod
* @param int $saltSize
* @param string $binaryData
*
* @throws ZipException
* @throws ZipUnsupportMethodException
*/
public function testExtraField(
$vendorVersion,
$keyStrength,
$compressionMethod,
$saltSize,
$binaryData
) {
int $vendorVersion,
int $keyStrength,
int $compressionMethod,
int $saltSize,
string $binaryData
): void {
$extraField = new WinZipAesExtraField($vendorVersion, $keyStrength, $compressionMethod);
self::assertSame($extraField->getHeaderId(), WinZipAesExtraField::HEADER_ID);
self::assertSame($extraField->getVendorVersion(), $vendorVersion);
@@ -50,10 +53,7 @@ final class WinZipAesExtraFieldTest extends TestCase
self::assertEquals(WinZipAesExtraField::unpackCentralDirData($binaryData), $extraField);
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -104,7 +104,7 @@ final class WinZipAesExtraFieldTest extends TestCase
/**
* @throws ZipUnsupportMethodException
*/
public function testSetter()
public function testSetter(): void
{
$extraField = new WinZipAesExtraField(
WinZipAesExtraField::VERSION_AE1,
@@ -155,9 +155,10 @@ final class WinZipAesExtraFieldTest extends TestCase
/**
* @throws ZipUnsupportMethodException
*/
public function testConstructUnsupportVendorVersion()
public function testConstructUnsupportVendorVersion(): void
{
$this->expectException(InvalidArgumentException::class, 'Unsupport WinZip AES vendor version: 3');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Unsupport WinZip AES vendor version: 3');
new WinZipAesExtraField(
3,
@@ -166,12 +167,10 @@ final class WinZipAesExtraFieldTest extends TestCase
);
}
/**
* @throws ZipUnsupportMethodException
*/
public function testSetterUnsupportVendorVersion()
public function testSetterUnsupportVendorVersion(): void
{
$this->expectException(InvalidArgumentException::class, 'Unsupport WinZip AES vendor version: 3');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Unsupport WinZip AES vendor version: 3');
$extraField = new WinZipAesExtraField(
WinZipAesExtraField::VERSION_AE1,
@@ -181,12 +180,10 @@ final class WinZipAesExtraFieldTest extends TestCase
$extraField->setVendorVersion(3);
}
/**
* @throws ZipUnsupportMethodException
*/
public function testConstructUnsupportCompressionMethod()
public function testConstructUnsupportCompressionMethod(): void
{
$this->expectException(ZipUnsupportMethodException::class, 'Compression method 3 (Reduced compression factor 2) is not supported.');
$this->expectException(ZipUnsupportMethodException::class);
$this->expectExceptionMessage('Compression method 3 (Reduced compression factor 2) is not supported.');
new WinZipAesExtraField(
WinZipAesExtraField::VERSION_AE1,
@@ -195,12 +192,10 @@ final class WinZipAesExtraFieldTest extends TestCase
);
}
/**
* @throws ZipUnsupportMethodException
*/
public function testSetterUnsupportCompressionMethod()
public function testSetterUnsupportCompressionMethod(): void
{
$this->expectException(ZipUnsupportMethodException::class, 'Compression method 3 (Reduced compression factor 2) is not supported.');
$this->expectException(ZipUnsupportMethodException::class);
$this->expectExceptionMessage('Compression method 3 (Reduced compression factor 2) is not supported.');
$extraField = new WinZipAesExtraField(
WinZipAesExtraField::VERSION_AE1,
@@ -213,9 +208,10 @@ final class WinZipAesExtraFieldTest extends TestCase
/**
* @throws ZipUnsupportMethodException
*/
public function testConstructUnsupportKeyStrength()
public function testConstructUnsupportKeyStrength(): void
{
$this->expectException(InvalidArgumentException::class, 'Key strength 16 not support value. Allow values: 1, 2, 3');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Key strength 16 not support value. Allow values: 1, 2, 3');
new WinZipAesExtraField(
WinZipAesExtraField::VERSION_AE1,
@@ -225,11 +221,12 @@ final class WinZipAesExtraFieldTest extends TestCase
}
/**
* @throws ZipUnsupportMethodException
* @throws ZipException
*/
public function testSetterUnsupportKeyStrength()
public function testSetterUnsupportKeyStrength(): void
{
$this->expectException(InvalidArgumentException::class, 'Key strength 16 not support value. Allow values: 1, 2, 3');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Key strength 16 not support value. Allow values: 1, 2, 3');
new WinZipAesExtraField(
WinZipAesExtraField::VERSION_AE1,

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* This file is part of the nelexa/zip package.
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpZip\Tests\Extra\Fields;
use PHPUnit\Framework\TestCase;
@@ -25,25 +34,25 @@ final class Zip64ExtraFieldTest extends TestCase
/**
* @dataProvider provideExtraField
*
* @param int|null $uncompressedSize
* @param int|null $compressedSize
* @param int|null $localHeaderOffset
* @param int|null $diskStart
* @param string|null $localBinaryData
* @param string|null $cdBinaryData
* @noinspection PhpTooManyParametersInspection
*
* @param ?int $uncompressedSize
* @param ?int $compressedSize
* @param ?int $localHeaderOffset
* @param ?int $diskStart
* @param ?string $localBinaryData
* @param ?string $cdBinaryData
*
* @throws ZipException
*
* @noinspection PhpTooManyParametersInspection
*/
public function testExtraField(
$uncompressedSize,
$compressedSize,
$localHeaderOffset,
$diskStart,
$localBinaryData,
$cdBinaryData
) {
?int $uncompressedSize,
?int $compressedSize,
?int $localHeaderOffset,
?int $diskStart,
?string $localBinaryData,
?string $cdBinaryData
): void {
$extraField = new Zip64ExtraField(
$uncompressedSize,
$compressedSize,
@@ -72,10 +81,7 @@ final class Zip64ExtraFieldTest extends TestCase
}
}
/**
* @return array
*/
public function provideExtraField()
public function provideExtraField(): array
{
return [
[
@@ -105,7 +111,7 @@ final class Zip64ExtraFieldTest extends TestCase
];
}
public function testSetter()
public function testSetter(): void
{
$extraField = new Zip64ExtraField();
self::assertNull($extraField->getUncompressedSize());