From 8954da9e32c81f365af38256c9dbe03e0eea4aec Mon Sep 17 00:00:00 2001 From: Ne-Lexa Date: Sun, 16 May 2021 23:20:34 +0300 Subject: [PATCH] fix test for Windows issue #78 --- tests/Polyfill/PhpUnit9CompatTrait.php | 7 +++-- tests/SymlinkTest.php | 4 +-- tests/ZipFileTest.php | 40 ++++++++------------------ tests/ZipTestCase.php | 15 ---------- 4 files changed, 18 insertions(+), 48 deletions(-) diff --git a/tests/Polyfill/PhpUnit9CompatTrait.php b/tests/Polyfill/PhpUnit9CompatTrait.php index 1f0fc85..e853390 100644 --- a/tests/Polyfill/PhpUnit9CompatTrait.php +++ b/tests/Polyfill/PhpUnit9CompatTrait.php @@ -35,10 +35,13 @@ trait PhpUnit9CompatTrait /** * Asserts that a directory does not exist. * + * @noinspection PhpDeprecationInspection + * + * @param string $directory + * @param string $message + * * @throws ExpectationFailedException * @throws InvalidArgumentException - * - * @noinspection PhpDeprecationInspection */ public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void { diff --git a/tests/SymlinkTest.php b/tests/SymlinkTest.php index 6d2a7a4..358775f 100644 --- a/tests/SymlinkTest.php +++ b/tests/SymlinkTest.php @@ -23,9 +23,7 @@ final class SymlinkTest extends ZipTestCase */ public function testSymlink($allowSymlink) { - if (self::skipTestForWindows()) { - return; - } + self::skipTestForWindows(); if (!is_dir($this->outputDirname)) { self::assertTrue(mkdir($this->outputDirname, 0755, true)); diff --git a/tests/ZipFileTest.php b/tests/ZipFileTest.php index 9dfc738..1101fae 100644 --- a/tests/ZipFileTest.php +++ b/tests/ZipFileTest.php @@ -43,13 +43,8 @@ class ZipFileTest extends ZipTestCase */ public function testOpenFileCantOpen() { - if (static::skipTestForWindows()) { - return; - } - - if (static::skipTestForRootUser()) { - return; - } + static::skipTestForWindows(); + static::skipTestForRootUser(); $this->expectException(ZipException::class); $this->expectExceptionMessage('can\'t open'); @@ -186,9 +181,9 @@ class ZipFileTest extends ZipTestCase public function testOpenFromStreamInvalidResourceType2() { $this->expectException(InvalidArgumentException::class); - $exceptionMessage = PHP_VERSION_ID < 80000 ? - 'Invalid resource type' : - 'Stream must be a resource'; + $exceptionMessage = \PHP_VERSION_ID < 80000 + ? 'Invalid resource type' + : 'Stream must be a resource'; $this->expectExceptionMessage($exceptionMessage); $zipFile = new ZipFile(); @@ -1194,13 +1189,12 @@ class ZipFileTest extends ZipTestCase */ public function testExtractFail3() { + static::skipTestForWindows(); + static::skipTestForRootUser(); + $this->expectException(ZipException::class); $this->expectExceptionMessage('Destination is not writable directory'); - if (static::skipTestForRootUser()) { - return; - } - $zipFile = new ZipFile(); $zipFile['file'] = 'content'; $zipFile->saveAsFile($this->outputFilename); @@ -1453,13 +1447,8 @@ class ZipFileTest extends ZipTestCase */ public function testAddFileCannotOpen() { - if (static::skipTestForWindows()) { - return; - } - - if (static::skipTestForRootUser()) { - return; - } + static::skipTestForWindows(); + static::skipTestForRootUser(); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('is not readable'); @@ -1801,13 +1790,8 @@ class ZipFileTest extends ZipTestCase */ public function testSaveAsFileNotWritable() { - if (static::skipTestForWindows()) { - return; - } - - if (static::skipTestForRootUser()) { - return; - } + static::skipTestForWindows(); + static::skipTestForRootUser(); static::assertTrue(mkdir($this->outputDirname, 0444, true)); static::assertTrue(chmod($this->outputDirname, 0444)); diff --git a/tests/ZipTestCase.php b/tests/ZipTestCase.php index 993ee72..9db174f 100644 --- a/tests/ZipTestCase.php +++ b/tests/ZipTestCase.php @@ -192,32 +192,17 @@ abstract class ZipTestCase extends LegacyTestCase return null; } - /** - * @return bool - */ public static function skipTestForRootUser() { - /** @noinspection PhpComposerExtensionStubsInspection */ if (\extension_loaded('posix') && posix_getuid() === 0) { static::markTestSkipped('Skip the test for a user with root privileges'); - - return true; } - - return false; } - /** - * @return bool - */ public static function skipTestForWindows() { if (\DIRECTORY_SEPARATOR === '\\') { static::markTestSkipped('Skip on Windows'); - - return true; } - - return false; } }