Skip to content

Commit

Permalink
ci(unit-tests): test on windows
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Nov 10, 2021
1 parent f896bcf commit 100ad37
Show file tree
Hide file tree
Showing 52 changed files with 197 additions and 138 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
operating-system:
- "macos-latest"
- "ubuntu-latest"
- "windows-latest"

steps:
- name: "checkout"
Expand Down
4 changes: 2 additions & 2 deletions docs/component/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- [error_handle](./../../src/Psl/IO/error_handle.php#L17)
- [input_handle](./../../src/Psl/IO/input_handle.php#L17)
- [output_handle](./../../src/Psl/IO/output_handle.php#L17)
- [pipe](./../../src/Psl/IO/pipe.php#L24)
- [pipe](./../../src/Psl/IO/pipe.php#L26)

#### `Interfaces`

Expand All @@ -39,7 +39,7 @@
#### `Classes`

- [MemoryHandle](./../../src/Psl/IO/MemoryHandle.php#L15)
- [Reader](./../../src/Psl/IO/Reader.php#L15)
- [Reader](./../../src/Psl/IO/Reader.php#L17)

#### `Traits`

Expand Down
4 changes: 2 additions & 2 deletions docs/component/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#### `Functions`

- [escape_argument](./../../src/Psl/Shell/escape_argument.php#L17)
- [escape_argument](./../../src/Psl/Shell/escape_argument.php#L19)
- [escape_command](./../../src/Psl/Shell/escape_command.php#L14)
- [execute](./../../src/Psl/Shell/execute.php#L40)
- [execute](./../../src/Psl/Shell/execute.php#L45)


2 changes: 1 addition & 1 deletion docs/component/unix.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

#### `Classes`

- [Server](./../../src/Psl/Unix/Server.php#L15)
- [Server](./../../src/Psl/Unix/Server.php#L16)


2 changes: 0 additions & 2 deletions src/Psl/File/Internal/ResourceHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ final class ResourceHandle extends IO\Internal\ResourceHandle implements File\Re

/**
* @param resource|object $resource
*
* @throws Exception\BlockingException If unable to set the handle resource to non-blocking mode.
*/
public function __construct(string $path, mixed $resource, bool $read, bool $write)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/File/Internal/open.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* @internal
*
* @codeCoverageIgnore
*
* @throws IO\Exception\BlockingException If unable to set the handle resource to non-blocking mode.
*/
function open(string $filename, string $mode, bool $read, bool $write): ReadWriteHandleInterface
{
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/ReadHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ final class ReadHandle extends Internal\AbstractHandleWrapper implements ReadHan
/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $path does not point to a file, or is not readable.
*/
public function __construct(string $path)
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/ReadWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ final class ReadWriteHandle extends Internal\AbstractHandleWrapper implements Re
/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $path points to a non-file node, or it not writeable.
* @throws Filesystem\Exception\RuntimeException If unable to create $path when it does not exist.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/WriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ final class WriteHandle extends Internal\AbstractHandleWrapper implements WriteH
/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $filename points to a non-file node, or it not writeable.
* @throws Filesystem\Exception\RuntimeException If unable to create $path when it does not exist.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/open_read_only.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/**
* Open a file handle for read only.
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $path does not point to a file, or is not readable. *
*/
function open_read_only(string $path): ReadHandleInterface
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/open_read_write.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Open a file handle for read and write.
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $path points to a non-file node, or it not writeable.
* @throws Filesystem\Exception\RuntimeException If unable to create $path when it does not exist.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/open_write_only.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Open a file handle for write only.
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $filename points to a non-file node, or it not writeable.
* @throws Filesystem\Exception\RuntimeException If unable to create $path when it does not exist.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Psl/File/temporary.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @throws Psl\Exception\InvariantViolationException If $directory doesn't exist or is not writable.
* @throws Psl\Exception\InvariantViolationException If $prefix contains a directory separator.
* @throws Filesystem\Exception\RuntimeException If unable to create the file.
* @throws IO\Exception\BlockingException If unable to set the handle to non-blocking mode.
*/
function temporary(?string $directory = null, ?string $prefix = null): ReadWriteHandleInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Filesystem/create_temporary_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function create_temporary_file(?string $directory = null, ?string $prefix = null
}

try {
$filename = $directory . '/' . $prefix . SecureRandom\string(8);
$filename = $directory . SEPARATOR . $prefix . SecureRandom\string(8);
// @codeCoverageIgnoreStart
} catch (SecureRandom\Exception\InsufficientEntropyException $e) {
throw new Exception\RuntimeException('Unable to gather enough entropy to generate filename.', 0, $e);
Expand Down
9 changes: 0 additions & 9 deletions src/Psl/IO/Exception/BlockingException.php

This file was deleted.

15 changes: 4 additions & 11 deletions src/Psl/IO/Internal/ResourceHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use function stream_set_read_buffer;
use function strlen;
use function substr;
use const PHP_OS_FAMILY;

/**
* @internal
Expand Down Expand Up @@ -58,8 +59,6 @@ class ResourceHandle implements IO\CloseSeekReadWriteHandleInterface

/**
* @param resource|object $resource
*
* @throws Exception\BlockingException If unable to set the handle resource to non-blocking mode.
*/
public function __construct(mixed $resource, bool $read, bool $write, bool $seek)
{
Expand All @@ -70,17 +69,11 @@ public function __construct(mixed $resource, bool $read, bool $write, bool $seek

/** @psalm-suppress UnusedFunctionCall */
stream_set_read_buffer($resource, 0);
$result = stream_set_blocking($resource, false);
if ($result === false) {
$error = error_get_last();

throw new Exception\BlockingException(
$error['message'] ?? 'Unable to set the handle resource to non-blocking mode'
);
}
stream_set_blocking($resource, false);

$meta = stream_get_meta_data($resource);
$this->blocks = ($meta['wrapper_type'] ?? '') === 'plainfile';
$this->blocks = $meta['blocked'] || ($meta['wrapper_type'] ?? '') === 'plainfile';

if ($seek) {
$seekable = (bool)$meta['seekable'];

Expand Down
14 changes: 3 additions & 11 deletions src/Psl/IO/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use function strpos;
use function substr;

use const PHP_EOL;

final class Reader implements ReadHandleInterface
{
use ReadHandleConvenienceMethodsTrait;
Expand All @@ -32,7 +34,6 @@ public function __construct(ReadHandleInterface $handle)
* @param int $size The number of bytes to read.
*
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
* @throws Exception\RuntimeException If an error occurred during the operation,
* or reached end of file before requested size.
* @throws InvariantViolationException If $size is not positive.
Expand Down Expand Up @@ -79,7 +80,6 @@ function (): void {

/**
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
* @throws Exception\RuntimeException If an error occurred during the operation.
* @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle.
*/
Expand All @@ -97,7 +97,6 @@ private function fillBuffer(?int $desired_bytes, ?float $timeout): void
* Read a single byte from the handle.
*
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
* @throws Exception\RuntimeException If an error occurred during the operation, or reached end of file.
* @throws Psl\Exception\InvariantViolationException If $timeout is negative.
*/
Expand Down Expand Up @@ -138,12 +137,11 @@ public function readByte(?float $timeout = null): string
* or null if the end of file is reached before finding the current line terminator.
*
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
* @throws Exception\RuntimeException If an error occurred during the operation.
*/
public function readLine(): ?string
{
$line = $this->readUntil("\n");
$line = $this->readUntil(PHP_EOL);
if (null !== $line) {
return $line;
}
Expand All @@ -163,7 +161,6 @@ public function readLine(): ?string
* data.
*
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
* @throws Exception\RuntimeException If an error occurred during the operation.
*
* @psalm-suppress MissingThrowsDocblock
Expand Down Expand Up @@ -206,7 +203,6 @@ public function readUntil(string $suffix): ?string
* @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle.
* @throws InvariantViolationException If $max_bytes is 0.
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
*
* @return string the read data on success, or an empty string if the end of file is reached.
*
Expand Down Expand Up @@ -242,7 +238,6 @@ public function read(?int $max_bytes = null, ?float $timeout = null): string
* @throws Exception\RuntimeException If an error occurred during the operation.
* @throws InvariantViolationException If $max_bytes is 0.
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
*
* @return string the read data on success, or an empty string if the end of file is reached.
*
Expand Down Expand Up @@ -289,7 +284,6 @@ public function getHandle(): ReadHandleInterface
/**
* @throws Exception\RuntimeException If an error occurred during the operation.
* @throws Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\BlockingException If the handle is a socket or similar, and the read would block.
*
* @return bool true if EOL has been reached, false otherwise.
*/
Expand All @@ -313,8 +307,6 @@ public function isEndOfFile(): bool
$this->eof = true;
return true;
}
} catch (Exception\BlockingException) {
return false;
} catch (Exception\ExceptionInterface) {
// ignore; it'll be thrown again when attempting a real read.
}
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ final class CloseHandle implements IO\CloseHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseReadHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class CloseReadHandle implements IO\CloseReadHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseReadWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ final class CloseReadWriteHandle implements IO\CloseReadWriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseSeekHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ final class CloseSeekHandle implements IO\CloseSeekHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseSeekReadHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class CloseSeekReadHandle implements IO\CloseSeekReadHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseSeekReadWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ final class CloseSeekReadWriteHandle implements IO\CloseSeekReadWriteHandleInter

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseSeekWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class CloseSeekWriteHandle implements IO\CloseSeekWriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/CloseWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class CloseWriteHandle implements IO\CloseWriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/ReadHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class ReadHandle implements IO\ReadHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/ReadWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ final class ReadWriteHandle implements IO\ReadWriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/SeekHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ final class SeekHandle implements IO\SeekHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/SeekReadHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class SeekReadHandle implements IO\SeekReadHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/SeekReadWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ final class SeekReadWriteHandle implements IO\SeekReadWriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/SeekWriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class SeekWriteHandle implements IO\SeekWriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/IO/Stream/WriteHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class WriteHandle implements IO\WriteHandleInterface

/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
*/
public function __construct(mixed $stream)
{
Expand Down
Loading

0 comments on commit 100ad37

Please sign in to comment.