1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-08-05 06:57:25 +02:00

fix test for Windows

issue #78
This commit is contained in:
Ne-Lexa
2021-05-16 23:20:34 +03:00
parent c3523992ed
commit 8954da9e32
4 changed files with 18 additions and 48 deletions

View File

@@ -35,10 +35,13 @@ trait PhpUnit9CompatTrait
/** /**
* Asserts that a directory does not exist. * Asserts that a directory does not exist.
* *
* @noinspection PhpDeprecationInspection
*
* @param string $directory
* @param string $message
*
* @throws ExpectationFailedException * @throws ExpectationFailedException
* @throws InvalidArgumentException * @throws InvalidArgumentException
*
* @noinspection PhpDeprecationInspection
*/ */
public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void
{ {

View File

@@ -23,9 +23,7 @@ final class SymlinkTest extends ZipTestCase
*/ */
public function testSymlink($allowSymlink) public function testSymlink($allowSymlink)
{ {
if (self::skipTestForWindows()) { self::skipTestForWindows();
return;
}
if (!is_dir($this->outputDirname)) { if (!is_dir($this->outputDirname)) {
self::assertTrue(mkdir($this->outputDirname, 0755, true)); self::assertTrue(mkdir($this->outputDirname, 0755, true));

View File

@@ -43,13 +43,8 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testOpenFileCantOpen() public function testOpenFileCantOpen()
{ {
if (static::skipTestForWindows()) { static::skipTestForWindows();
return; static::skipTestForRootUser();
}
if (static::skipTestForRootUser()) {
return;
}
$this->expectException(ZipException::class); $this->expectException(ZipException::class);
$this->expectExceptionMessage('can\'t open'); $this->expectExceptionMessage('can\'t open');
@@ -186,9 +181,9 @@ class ZipFileTest extends ZipTestCase
public function testOpenFromStreamInvalidResourceType2() public function testOpenFromStreamInvalidResourceType2()
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$exceptionMessage = PHP_VERSION_ID < 80000 ? $exceptionMessage = \PHP_VERSION_ID < 80000
'Invalid resource type' : ? 'Invalid resource type'
'Stream must be a resource'; : 'Stream must be a resource';
$this->expectExceptionMessage($exceptionMessage); $this->expectExceptionMessage($exceptionMessage);
$zipFile = new ZipFile(); $zipFile = new ZipFile();
@@ -1194,13 +1189,12 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testExtractFail3() public function testExtractFail3()
{ {
static::skipTestForWindows();
static::skipTestForRootUser();
$this->expectException(ZipException::class); $this->expectException(ZipException::class);
$this->expectExceptionMessage('Destination is not writable directory'); $this->expectExceptionMessage('Destination is not writable directory');
if (static::skipTestForRootUser()) {
return;
}
$zipFile = new ZipFile(); $zipFile = new ZipFile();
$zipFile['file'] = 'content'; $zipFile['file'] = 'content';
$zipFile->saveAsFile($this->outputFilename); $zipFile->saveAsFile($this->outputFilename);
@@ -1453,13 +1447,8 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testAddFileCannotOpen() public function testAddFileCannotOpen()
{ {
if (static::skipTestForWindows()) { static::skipTestForWindows();
return; static::skipTestForRootUser();
}
if (static::skipTestForRootUser()) {
return;
}
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('is not readable'); $this->expectExceptionMessage('is not readable');
@@ -1801,13 +1790,8 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testSaveAsFileNotWritable() public function testSaveAsFileNotWritable()
{ {
if (static::skipTestForWindows()) { static::skipTestForWindows();
return; static::skipTestForRootUser();
}
if (static::skipTestForRootUser()) {
return;
}
static::assertTrue(mkdir($this->outputDirname, 0444, true)); static::assertTrue(mkdir($this->outputDirname, 0444, true));
static::assertTrue(chmod($this->outputDirname, 0444)); static::assertTrue(chmod($this->outputDirname, 0444));

View File

@@ -192,32 +192,17 @@ abstract class ZipTestCase extends LegacyTestCase
return null; return null;
} }
/**
* @return bool
*/
public static function skipTestForRootUser() public static function skipTestForRootUser()
{ {
/** @noinspection PhpComposerExtensionStubsInspection */
if (\extension_loaded('posix') && posix_getuid() === 0) { if (\extension_loaded('posix') && posix_getuid() === 0) {
static::markTestSkipped('Skip the test for a user with root privileges'); static::markTestSkipped('Skip the test for a user with root privileges');
return true;
} }
return false;
} }
/**
* @return bool
*/
public static function skipTestForWindows() public static function skipTestForWindows()
{ {
if (\DIRECTORY_SEPARATOR === '\\') { if (\DIRECTORY_SEPARATOR === '\\') {
static::markTestSkipped('Skip on Windows'); static::markTestSkipped('Skip on Windows');
return true;
} }
return false;
} }
} }