1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-07-12 11:46:20 +02:00
This commit is contained in:
Ne-Lexa
2021-05-21 09:02:22 +03:00
parent ac3533dece
commit c9130665cd
3 changed files with 19 additions and 29 deletions

View File

@ -15,7 +15,7 @@ use PhpZip\ZipFile;
* *
* @small * @small
*/ */
class PhpZipExtResourceTest extends ZipTestCase final class PhpZipExtResourceTest extends ZipTestCase
{ {
/** /**
* Bug #7214 (zip_entry_read() binary safe). * Bug #7214 (zip_entry_read() binary safe).
@ -33,11 +33,11 @@ class PhpZipExtResourceTest extends ZipTestCase
foreach ($zipFile as $name => $contents) { foreach ($zipFile as $name => $contents) {
$info = $zipFile->getEntryInfo($name); $info = $zipFile->getEntryInfo($name);
static::assertSame(\strlen($contents), $info->getSize()); self::assertSame(\strlen($contents), $info->getSize());
} }
$zipFile->close(); $zipFile->close();
static::assertCorrectZipArchive($filename); self::assertCorrectZipArchive($filename);
} }
/** /**
@ -57,13 +57,13 @@ class PhpZipExtResourceTest extends ZipTestCase
$zipFile->saveAsFile($this->outputFilename); $zipFile->saveAsFile($this->outputFilename);
$zipFile->close(); $zipFile->close();
static::assertCorrectZipArchive($this->outputFilename); self::assertCorrectZipArchive($this->outputFilename);
$zipFile->openFile($this->outputFilename); $zipFile->openFile($this->outputFilename);
static::assertCount(2, $zipFile); self::assertCount(2, $zipFile);
static::assertTrue(isset($zipFile['1.txt'])); self::assertTrue(isset($zipFile['1.txt']));
static::assertTrue(isset($zipFile['2.txt'])); self::assertTrue(isset($zipFile['2.txt']));
static::assertSame($zipFile['2.txt'], $zipFile['1.txt']); self::assertSame($zipFile['2.txt'], $zipFile['1.txt']);
$zipFile->close(); $zipFile->close();
} }
@ -80,14 +80,14 @@ class PhpZipExtResourceTest extends ZipTestCase
*/ */
public function testBug40228($filename) public function testBug40228($filename)
{ {
static::assertTrue(mkdir($this->outputDirname, 0755, true)); self::assertTrue(mkdir($this->outputDirname, 0755, true));
$zipFile = new ZipFile(); $zipFile = new ZipFile();
$zipFile->openFile($filename); $zipFile->openFile($filename);
$zipFile->extractTo($this->outputDirname); $zipFile->extractTo($this->outputDirname);
$zipFile->close(); $zipFile->close();
static::assertDirectoryExists($this->outputDirname . '/test/empty'); self::assertDirectoryExists($this->outputDirname . '/test/empty');
} }
/** /**
@ -129,24 +129,16 @@ class PhpZipExtResourceTest extends ZipTestCase
public function testBug70752() public function testBug70752()
{ {
if (\PHP_INT_SIZE === 4) { // php 32 bit if (\PHP_INT_SIZE === 4) { // php 32 bit
$this->expectException( $this->expectException(RuntimeException::class);
RuntimeException::class $this->expectExceptionMessage('Traditional PKWARE Encryption is not supported in 32-bit PHP.');
);
$this->expectExceptionMessage(
'Traditional PKWARE Encryption is not supported in 32-bit PHP.'
);
} else { // php 64 bit } else { // php 64 bit
$this->expectException( $this->expectException(ZipAuthenticationException::class);
ZipAuthenticationException::class $this->expectExceptionMessage('Invalid password');
);
$this->expectExceptionMessage(
'Invalid password'
);
} }
$filename = __DIR__ . '/resources/pecl/bug70752.zip'; $filename = __DIR__ . '/resources/pecl/bug70752.zip';
static::assertTrue(mkdir($this->outputDirname, 0755, true)); self::assertTrue(mkdir($this->outputDirname, 0755, true));
$zipFile = new ZipFile(); $zipFile = new ZipFile();
$zipFile->openFile($filename); $zipFile->openFile($filename);
@ -154,9 +146,9 @@ class PhpZipExtResourceTest extends ZipTestCase
try { try {
$zipFile->extractTo($this->outputDirname); $zipFile->extractTo($this->outputDirname);
static::markTestIncomplete('failed test'); self::markTestIncomplete('failed test');
} catch (ZipException $exception) { } catch (ZipException $exception) {
static::assertFileDoesNotExist($this->outputDirname . '/bug70752.txt'); self::assertFileDoesNotExist($this->outputDirname . '/bug70752.txt');
throw $exception; throw $exception;
} }

View File

@ -24,7 +24,7 @@ trait PhpUnit9CompatTrait
public static function assertFileDoesNotExist(string $filename, string $message = ''): void public static function assertFileDoesNotExist(string $filename, string $message = ''): void
{ {
if (version_compare(Version::id(), '9.1.0', '<')) { if (version_compare(Version::id(), '9.1.0', '<')) {
static::assertFileNotExists($filename, $message); self::assertFileNotExists($filename, $message);
return; return;
} }
@ -46,7 +46,7 @@ trait PhpUnit9CompatTrait
public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void
{ {
if (version_compare(Version::id(), '9.1.0', '<')) { if (version_compare(Version::id(), '9.1.0', '<')) {
static::assertDirectoryNotExists($directory, $message); self::assertDirectoryNotExists($directory, $message);
return; return;
} }

View File

@ -450,8 +450,6 @@ class ZipFileTest extends ZipTestCase
{ {
if (!\function_exists('mime_content_type')) { if (!\function_exists('mime_content_type')) {
static::markTestSkipped('Function mime_content_type not exists'); static::markTestSkipped('Function mime_content_type not exists');
return;
} }
$outputFilename = $this->outputFilename; $outputFilename = $this->outputFilename;
$this->outputFilename .= '.gif'; $this->outputFilename .= '.gif';