Skip to content

Commit

Permalink
fix test for Windows
Browse files Browse the repository at this point in the history
issue #78
  • Loading branch information
Ne-Lexa committed May 16, 2021
1 parent c352399 commit 8954da9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 48 deletions.
7 changes: 5 additions & 2 deletions tests/Polyfill/PhpUnit9CompatTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ public static function assertFileDoesNotExist(string $filename, string $message
/**
* 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
{
Expand Down
4 changes: 1 addition & 3 deletions tests/SymlinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
40 changes: 12 additions & 28 deletions tests/ZipFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ public function testOpenFileCantExists()
*/
public function testOpenFileCantOpen()
{
if (static::skipTestForWindows()) {
return;
}

if (static::skipTestForRootUser()) {
return;
}
static::skipTestForWindows();
static::skipTestForRootUser();

$this->expectException(ZipException::class);
$this->expectExceptionMessage('can\'t open');
Expand Down Expand Up @@ -186,9 +181,9 @@ public function testOpenFromStreamInvalidResourceType()
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();
Expand Down Expand Up @@ -1194,13 +1189,12 @@ public function testExtractFail2()
*/
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);
Expand Down Expand Up @@ -1453,13 +1447,8 @@ public function testAddFileUnsupportedMethod()
*/
public function testAddFileCannotOpen()
{
if (static::skipTestForWindows()) {
return;
}

if (static::skipTestForRootUser()) {
return;
}
static::skipTestForWindows();
static::skipTestForRootUser();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('is not readable');
Expand Down Expand Up @@ -1801,13 +1790,8 @@ public function testSaveAsStreamBadStream()
*/
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));
Expand Down
15 changes: 0 additions & 15 deletions tests/ZipTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,32 +192,17 @@ public static function assertVerifyZipAlign($filename, $showErrors = false)
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;
}
}

0 comments on commit 8954da9

Please sign in to comment.