From d9d24bb96e7c1ff105c568ea512feace8d76003a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 17 May 2025 17:37:03 +0200 Subject: [PATCH] update dependencies --- CHANGELOG.md | 18 +++++++ composer.json | 21 ++++---- src/Config.php | 67 ++++--------------------- src/CurrentProcess/Generic.php | 3 +- src/Filesystem/Generic.php | 41 +++++++-------- src/Filesystem/Logger.php | 7 +-- src/OperatingSystem/Logger.php | 4 +- src/OperatingSystem/Unix.php | 2 +- src/Ports.php | 6 ++- src/Ports/Logger.php | 2 +- src/Ports/Unix.php | 17 +++---- src/Remote.php | 6 ++- src/Remote/Generic.php | 18 +++---- src/Remote/Logger.php | 2 +- src/Remote/Resilient.php | 25 +++++++-- src/Sockets.php | 17 +++---- src/Sockets/Logger.php | 13 +---- src/Sockets/Unix.php | 52 ++++++++----------- tests/CurrentProcess/GenericTest.php | 9 +--- tests/CurrentProcess/LoggerTest.php | 4 +- tests/FactoryTest.php | 9 ++-- tests/Filesystem/LoggerTest.php | 17 +++++-- tests/OperatingSystem/LoggerTest.php | 2 +- tests/OperatingSystem/ResilientTest.php | 3 +- tests/OperatingSystem/UnixTest.php | 2 +- tests/Ports/LoggerTest.php | 6 +-- tests/Ports/UnixTest.php | 8 +-- tests/Remote/GenericTest.php | 28 +++++++---- tests/Remote/LoggerTest.php | 6 +-- tests/Remote/ResilientTest.php | 6 +-- tests/Sockets/LoggerTest.php | 49 ++++-------------- tests/Sockets/UnixTest.php | 49 +++++++----------- 32 files changed, 224 insertions(+), 295 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c14ca1d..8543533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,28 @@ ## [Unreleased] +### Changed + +- Requires `innmind/time-continuum:^4.1.1` +- Requires `innmind/server-status:~5.0` +- Requires `innmind/server-control:~6.0` +- Requires `innmind/filesystem:~8.1` +- Requires `innmind/file-watch:~5.0` +- Requires `innmind/http-transport:~8.0` +- Requires `innmind/time-warp:~4.0` +- Requires `innmind/io:~3.2` +- Requires `innmind/immutable:~5.15` +- `Innmind\OperatingSystem\Config::withHttpHeartbeat()` period is now expressed with a `Innmind\TimeContinuum\Period` + ### Fixed - PHP `8.4` deprecations +### Removed + +- `Innmind\OperatingSystem\Config::useStreamCapabilities()` +- `Innmind\OperatingSystem\Sockets::watch()` + ## 5.2.0 - 2024-07-14 ### Changed diff --git a/composer.json b/composer.json index 7b34153..a22a454 100644 --- a/composer.json +++ b/composer.json @@ -16,18 +16,17 @@ }, "require": { "php": "~8.2", - "innmind/time-continuum": "~3.0", - "innmind/server-status": "~4.0", - "innmind/server-control": "~5.0", - "innmind/filesystem": "~7.1", - "innmind/socket": "~6.0", - "innmind/http-transport": "~7.2", - "innmind/time-warp": "~3.0", + "innmind/time-continuum": "^4.1.1", + "innmind/server-status": "~5.0", + "innmind/server-control": "~6.0", + "innmind/filesystem": "~8.1", + "innmind/http-transport": "~8.0", + "innmind/time-warp": "~4.0", "innmind/signals": "~3.0", - "innmind/file-watch": "~4.0", - "innmind/stream": "~4.0", + "innmind/file-watch": "~5.0", "formal/access-layer": "~4.0", - "innmind/io": "~2.7" + "innmind/io": "~3.2", + "innmind/immutable": "~5.15" }, "autoload": { "psr-4": { @@ -44,7 +43,7 @@ "innmind/url": "~4.0", "innmind/ip": "~3.0", "innmind/static-analysis": "^1.2.1", - "innmind/black-box": "~5.5", + "innmind/black-box": "~6.2", "innmind/coding-standard": "~2.0" } } diff --git a/src/Config.php b/src/Config.php index 25bb955..286b725 100644 --- a/src/Config.php +++ b/src/Config.php @@ -5,41 +5,34 @@ use Innmind\TimeContinuum\{ Clock, - Earth, - ElapsedPeriod, + Period, }; use Innmind\Filesystem\CaseSensitivity; use Innmind\Server\Status\EnvironmentPath; use Innmind\TimeWarp\Halt; use Innmind\IO\IO; -use Innmind\Stream\{ - Capabilities, - Streams, -}; use Innmind\Immutable\Maybe; final class Config { private Clock $clock; private CaseSensitivity $caseSensitivity; - private Capabilities $streamCapabilities; private IO $io; private Halt $halt; private EnvironmentPath $path; /** @var Maybe */ private Maybe $maxHttpConcurrency; - /** @var Maybe */ + /** @var Maybe */ private Maybe $httpHeartbeat; private bool $disableSSLVerification; /** * @param Maybe $maxHttpConcurrency - * @param Maybe $httpHeartbeat + * @param Maybe $httpHeartbeat */ private function __construct( Clock $clock, CaseSensitivity $caseSensitivity, - Capabilities $streamCapabilities, IO $io, Halt $halt, EnvironmentPath $path, @@ -49,7 +42,6 @@ private function __construct( ) { $this->clock = $clock; $this->caseSensitivity = $caseSensitivity; - $this->streamCapabilities = $streamCapabilities; $this->io = $io; $this->halt = $halt; $this->path = $path; @@ -62,18 +54,14 @@ public static function of(): self { /** @var Maybe */ $maxHttpConcurrency = Maybe::nothing(); - /** @var Maybe */ + /** @var Maybe */ $httpHeartbeat = Maybe::nothing(); return new self( - new Earth\Clock, + Clock::live(), CaseSensitivity::sensitive, - $streams = Streams::fromAmbientAuthority(), - IO::of(static fn(?ElapsedPeriod $timeout) => match ($timeout) { - null => $streams->watch()->waitForever(), - default => $streams->watch()->timeoutAfter($timeout), - }), - new Halt\Usleep, + IO::fromAmbientAuthority(), + Halt\Usleep::new(), EnvironmentPath::of(match ($path = \getenv('PATH')) { false => '', default => $path, @@ -92,7 +80,6 @@ public function withClock(Clock $clock): self return new self( $clock, $this->caseSensitivity, - $this->streamCapabilities, $this->io, $this->halt, $this->path, @@ -110,7 +97,6 @@ public function caseInsensitiveFilesystem(): self return new self( $this->clock, CaseSensitivity::insensitive, - $this->streamCapabilities, $this->io, $this->halt, $this->path, @@ -120,28 +106,6 @@ public function caseInsensitiveFilesystem(): self ); } - /** - * @psalm-mutation-free - */ - public function useStreamCapabilities(Capabilities $capabilities): self - { - /** @psalm-suppress ImpureMethodCall This should be solved in the next innmind/io release */ - return new self( - $this->clock, - $this->caseSensitivity, - $capabilities, - IO::of(static fn(?ElapsedPeriod $timeout) => match ($timeout) { - null => $capabilities->watch()->waitForever(), - default => $capabilities->watch()->timeoutAfter($timeout), - }), - $this->halt, - $this->path, - $this->maxHttpConcurrency, - $this->httpHeartbeat, - $this->disableSSLVerification, - ); - } - /** * @psalm-mutation-free */ @@ -150,7 +114,6 @@ public function haltProcessVia(Halt $halt): self return new self( $this->clock, $this->caseSensitivity, - $this->streamCapabilities, $this->io, $halt, $this->path, @@ -168,7 +131,6 @@ public function withEnvironmentPath(EnvironmentPath $path): self return new self( $this->clock, $this->caseSensitivity, - $this->streamCapabilities, $this->io, $this->halt, $path, @@ -188,7 +150,6 @@ public function limitHttpConcurrencyTo(int $max): self return new self( $this->clock, $this->caseSensitivity, - $this->streamCapabilities, $this->io, $this->halt, $this->path, @@ -203,12 +164,11 @@ public function limitHttpConcurrencyTo(int $max): self * * @param callable(): void $heartbeat */ - public function withHttpHeartbeat(ElapsedPeriod $timeout, callable $heartbeat): self + public function withHttpHeartbeat(Period $timeout, callable $heartbeat): self { return new self( $this->clock, $this->caseSensitivity, - $this->streamCapabilities, $this->io, $this->halt, $this->path, @@ -226,7 +186,6 @@ public function disableSSLVerification(): self return new self( $this->clock, $this->caseSensitivity, - $this->streamCapabilities, $this->io, $this->halt, $this->path, @@ -252,14 +211,6 @@ public function filesystemCaseSensitivity(): CaseSensitivity return $this->caseSensitivity; } - /** - * @internal - */ - public function streamCapabilities(): Capabilities - { - return $this->streamCapabilities; - } - /** * @internal */ @@ -297,7 +248,7 @@ public function maxHttpConcurrency(): Maybe /** * @internal * - * @return Maybe + * @return Maybe */ public function httpHeartbeat(): Maybe { diff --git a/src/CurrentProcess/Generic.php b/src/CurrentProcess/Generic.php index 101d200..a39361f 100644 --- a/src/CurrentProcess/Generic.php +++ b/src/CurrentProcess/Generic.php @@ -53,6 +53,7 @@ public function halt(Period $period): void #[\Override] public function memory(): Bytes { - return new Bytes(\memory_get_usage()); + /** @psalm-suppress ArgumentTypeCoercion */ + return Bytes::of(\memory_get_usage()); } } diff --git a/src/Filesystem/Generic.php b/src/Filesystem/Generic.php index ff3cbfc..6fa1464 100644 --- a/src/Filesystem/Generic.php +++ b/src/Filesystem/Generic.php @@ -18,12 +18,10 @@ Factory, Watch, }; -use Innmind\Stream\Bidirectional; use Innmind\Immutable\{ Maybe, + Attempt, Sequence, - Str, - Predicate\Instance, }; final class Generic implements Filesystem @@ -64,7 +62,6 @@ public function mount(Path $path): Adapter $adapter = Adapter\Filesystem::mount( $path, - $this->config->streamCapabilities(), $this->config->io(), ) ->withCaseSensitivity( @@ -116,24 +113,22 @@ public function watch(Path $path): Ping #[\Override] public function temporary(Sequence $chunks): Maybe { - $temporary = $this - ->config - ->streamCapabilities() - ->temporary() - ->new(); - - $temporary = $chunks->reduce( - Maybe::just($temporary), - static fn(Maybe $temporary, $chunk) => Maybe::all($temporary, $chunk)->flatMap( - static fn(Bidirectional $temporary, Str $chunk) => $temporary - ->write($chunk->toEncoding(Str\Encoding::ascii)) - ->maybe() - ->keep(Instance::of(Bidirectional::class)), - ), - ); - - return $temporary - ->map($this->config->io()->readable()->wrap(...)) - ->map(Content::io(...)); + return Attempt::of( + fn() => $this + ->config + ->io() + ->files() + ->temporary( + $chunks->map( + static fn($chunk) => $chunk + ->attempt(static fn() => new \RuntimeException('Failed to load chunk')) + ->unwrap(), + ), + ) + ->memoize() // to make sure writing the chunks has been done + ->map(static fn($tmp) => $tmp->read()) + ->map(Content::io(...)) + ->unwrap(), + )->maybe(); } } diff --git a/src/Filesystem/Logger.php b/src/Filesystem/Logger.php index 58995aa..9019dc0 100644 --- a/src/Filesystem/Logger.php +++ b/src/Filesystem/Logger.php @@ -77,11 +77,8 @@ public function require(Path $path): Maybe #[\Override] public function watch(Path $path): Ping { - return Ping\Logger::psr( - $this->filesystem->watch($path), - $path, - $this->logger, - ); + // todo bring back the ping logger + return $this->filesystem->watch($path); } #[\Override] diff --git a/src/OperatingSystem/Logger.php b/src/OperatingSystem/Logger.php index 334af63..900dc03 100644 --- a/src/OperatingSystem/Logger.php +++ b/src/OperatingSystem/Logger.php @@ -44,7 +44,7 @@ public function map(callable $map): OperatingSystem #[\Override] public function clock(): TimeContinuum\Clock { - return new TimeContinuum\Logger\Clock( + return TimeContinuum\Clock::logger( $this->os->clock(), $this->logger, ); @@ -62,7 +62,7 @@ public function filesystem(): Filesystem #[\Override] public function status(): Status\Server { - return new Status\Servers\Logger( + return Status\Servers\Logger::of( $this->os->status(), $this->logger, ); diff --git a/src/OperatingSystem/Unix.php b/src/OperatingSystem/Unix.php index dfa6742..04044ac 100644 --- a/src/OperatingSystem/Unix.php +++ b/src/OperatingSystem/Unix.php @@ -79,7 +79,7 @@ public function control(): ServerControl { return $this->control ??= Servers\Unix::of( $this->clock(), - $this->config->streamCapabilities(), + $this->config->io(), $this->config->halt(), ); } diff --git a/src/Ports.php b/src/Ports.php index c46e89f..b2f4433 100644 --- a/src/Ports.php +++ b/src/Ports.php @@ -4,8 +4,10 @@ namespace Innmind\OperatingSystem; use Innmind\Url\Authority\Port; -use Innmind\IO\Sockets\Server; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\{ + Sockets\Servers\Server, + Sockets\Internet\Transport, +}; use Innmind\IP\IP; use Innmind\Immutable\Maybe; diff --git a/src/Ports/Logger.php b/src/Ports/Logger.php index 3424d5f..8fed62b 100644 --- a/src/Ports/Logger.php +++ b/src/Ports/Logger.php @@ -5,7 +5,7 @@ use Innmind\OperatingSystem\Ports; use Innmind\Url\Authority\Port; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\IP\IP; use Innmind\Immutable\Maybe; use Psr\Log\LoggerInterface; diff --git a/src/Ports/Unix.php b/src/Ports/Unix.php index 6601d1a..dc25700 100644 --- a/src/Ports/Unix.php +++ b/src/Ports/Unix.php @@ -8,11 +8,7 @@ Config, }; use Innmind\Url\Authority\Port; -use Innmind\IO\Sockets\Server; -use Innmind\Socket\{ - Internet\Transport, - Server\Internet, -}; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\IP\IP; use Innmind\Immutable\Maybe; @@ -36,9 +32,12 @@ public static function of(Config $config): self #[\Override] public function open(Transport $transport, IP $ip, Port $port): Maybe { - /** @var Maybe */ - return Internet::of($transport, $ip, $port)->map( - $this->config->io()->sockets()->servers()->wrap(...), - ); + return $this + ->config + ->io() + ->sockets() + ->servers() + ->internet($transport, $ip, $port) + ->maybe(); } } diff --git a/src/Remote.php b/src/Remote.php index afcd615..0a2cf9a 100644 --- a/src/Remote.php +++ b/src/Remote.php @@ -4,8 +4,10 @@ namespace Innmind\OperatingSystem; use Innmind\Server\Control\Server; -use Innmind\Socket\Internet\Transport; -use Innmind\IO\Sockets\Client; +use Innmind\IO\{ + Sockets\Clients\Client, + Sockets\Internet\Transport, +}; use Innmind\Url\{ Url, Authority, diff --git a/src/Remote/Generic.php b/src/Remote/Generic.php index 47d8985..de95406 100644 --- a/src/Remote/Generic.php +++ b/src/Remote/Generic.php @@ -11,10 +11,7 @@ Server, Servers, }; -use Innmind\Socket\{ - Internet\Transport, - Client, -}; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\Url\{ Url, Authority, @@ -56,7 +53,7 @@ public function ssh(Url $server): Server $port = $server->authority()->port(); } - return new Servers\Remote( + return Servers\Remote::of( $this->server, $server->authority()->userInformation()->user(), $server->authority()->host(), @@ -67,9 +64,13 @@ public function ssh(Url $server): Server #[\Override] public function socket(Transport $transport, Authority $authority): Maybe { - return Client\Internet::of($transport, $authority)->map( - $this->config->io()->sockets()->clients()->wrap(...), - ); + return $this + ->config + ->io() + ->sockets() + ->clients() + ->internet($transport, $authority) + ->maybe(); } #[\Override] @@ -81,7 +82,6 @@ public function http(): HttpTransport $http = Curl::of( $this->config->clock(), - $this->config->streamCapabilities(), $this->config->io(), ); $http = $this->config->maxHttpConcurrency()->match( diff --git a/src/Remote/Logger.php b/src/Remote/Logger.php index 8b6f4bb..9db7403 100644 --- a/src/Remote/Logger.php +++ b/src/Remote/Logger.php @@ -5,7 +5,7 @@ use Innmind\OperatingSystem\Remote; use Innmind\Server\Control; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\Url\{ Url, Authority, diff --git a/src/Remote/Resilient.php b/src/Remote/Resilient.php index 2c905f8..daf09b8 100644 --- a/src/Remote/Resilient.php +++ b/src/Remote/Resilient.php @@ -8,7 +8,9 @@ CurrentProcess, }; use Innmind\Server\Control\Server; -use Innmind\Socket\Internet\Transport; +use Innmind\TimeWarp\Halt; +use Innmind\TimeContinuum\Period; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\Url\{ Url, Authority, @@ -17,7 +19,11 @@ Transport as HttpTransport, ExponentialBackoff, }; -use Innmind\Immutable\Maybe; +use Innmind\Immutable\{ + Maybe, + Attempt, + SideEffect, +}; use Formal\AccessLayer\Connection; final class Resilient implements Remote @@ -53,7 +59,20 @@ public function http(): HttpTransport { return ExponentialBackoff::of( $this->remote->http(), - $this->process->halt(...), + new class($this->process) implements Halt { + public function __construct( + private CurrentProcess $process, + ) { + } + + #[\Override] + public function __invoke(Period $period): Attempt + { + $this->process->halt($period); + + return Attempt::result(SideEffect::identity()); + } + }, ); } diff --git a/src/Sockets.php b/src/Sockets.php index 44b045a..b5f1d83 100644 --- a/src/Sockets.php +++ b/src/Sockets.php @@ -3,13 +3,11 @@ namespace Innmind\OperatingSystem; -use Innmind\IO\Sockets\{ - Client, - Server, +use Innmind\IO\{ + Sockets\Clients\Client, + Sockets\Servers\Server, + Sockets\Unix\Address, }; -use Innmind\Socket\Address\Unix; -use Innmind\TimeContinuum\ElapsedPeriod; -use Innmind\Stream\Watch; use Innmind\Immutable\Maybe; interface Sockets @@ -19,18 +17,17 @@ interface Sockets * * @return Maybe */ - public function open(Unix $address): Maybe; + public function open(Address $address): Maybe; /** * This will take control of the socket if it already exist (use carefully) * * @return Maybe */ - public function takeOver(Unix $address): Maybe; + public function takeOver(Address $address): Maybe; /** * @return Maybe */ - public function connectTo(Unix $address): Maybe; - public function watch(?ElapsedPeriod $timeout = null): Watch; + public function connectTo(Address $address): Maybe; } diff --git a/src/Sockets/Logger.php b/src/Sockets/Logger.php index d43fff1..3c2fba3 100644 --- a/src/Sockets/Logger.php +++ b/src/Sockets/Logger.php @@ -4,9 +4,7 @@ namespace Innmind\OperatingSystem\Sockets; use Innmind\OperatingSystem\Sockets; -use Innmind\Socket\Address\Unix as Address; -use Innmind\TimeContinuum\ElapsedPeriod; -use Innmind\Stream\Watch; +use Innmind\IO\Sockets\Unix\Address; use Innmind\Immutable\Maybe; use Psr\Log\LoggerInterface; @@ -58,13 +56,4 @@ public function connectTo(Address $address): Maybe return $this->sockets->connectTo($address); } - - #[\Override] - public function watch(?ElapsedPeriod $timeout = null): Watch - { - return Watch\Logger::psr( - $this->sockets->watch($timeout), - $this->logger, - ); - } } diff --git a/src/Sockets/Unix.php b/src/Sockets/Unix.php index ab87a31..f169224 100644 --- a/src/Sockets/Unix.php +++ b/src/Sockets/Unix.php @@ -7,13 +7,7 @@ Sockets, Config, }; -use Innmind\Socket\{ - Address\Unix as Address, - Server, - Client, -}; -use Innmind\TimeContinuum\ElapsedPeriod; -use Innmind\Stream\Watch; +use Innmind\IO\Sockets\Unix\Address; use Innmind\Immutable\Maybe; final class Unix implements Sockets @@ -36,42 +30,36 @@ public static function of(Config $config): self #[\Override] public function open(Address $address): Maybe { - return Server\Unix::of($address)->map( - $this->config->io()->sockets()->servers()->wrap(...), - ); + return $this + ->config + ->io() + ->sockets() + ->servers() + ->unix($address) + ->maybe(); } #[\Override] public function takeOver(Address $address): Maybe { - return Server\Unix::recoverable($address)->map( - $this->config->io()->sockets()->servers()->wrap(...), - ); + return $this + ->config + ->io() + ->sockets() + ->servers() + ->takeOver($address) + ->maybe(); } #[\Override] public function connectTo(Address $address): Maybe { - return Client\Unix::of($address)->map( - $this->config->io()->sockets()->clients()->wrap(...), - ); - } - - #[\Override] - public function watch(?ElapsedPeriod $timeout = null): Watch - { - if (\is_null($timeout)) { - return $this - ->config - ->streamCapabilities() - ->watch() - ->waitForever(); - } - return $this ->config - ->streamCapabilities() - ->watch() - ->timeoutAfter($timeout); + ->io() + ->sockets() + ->clients() + ->unix($address) + ->maybe(); } } diff --git a/tests/CurrentProcess/GenericTest.php b/tests/CurrentProcess/GenericTest.php index 668a17a..0c14cd7 100644 --- a/tests/CurrentProcess/GenericTest.php +++ b/tests/CurrentProcess/GenericTest.php @@ -35,15 +35,10 @@ public function testId() public function testHalt() { $process = Generic::of( - $halt = $this->createMock(Halt::class), + Halt\Usleep::new(), ); - $period = $this->createMock(Period::class); - $halt - ->expects($this->once()) - ->method('__invoke') - ->with($period); - $this->assertNull($process->halt($period)); + $this->assertNull($process->halt(Period::millisecond(1))); } public function testSignals() diff --git a/tests/CurrentProcess/LoggerTest.php b/tests/CurrentProcess/LoggerTest.php index 812fe6b..f8cec43 100644 --- a/tests/CurrentProcess/LoggerTest.php +++ b/tests/CurrentProcess/LoggerTest.php @@ -69,7 +69,7 @@ public function testAlwaysUseSameSignalInstance() public function testHalt() { - $period = $this->createMock(Period::class); + $period = Period::millisecond(1); $inner = $this->createMock(CurrentProcess::class); $inner ->expects($this->once()) @@ -94,7 +94,7 @@ public function testMemory() $inner ->expects($this->once()) ->method('memory') - ->willReturn($expected = new Bytes($memory)); + ->willReturn($expected = Bytes::of($memory)); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index ec5d0d2..db0786f 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -8,10 +8,7 @@ OperatingSystem\Unix, Config, }; -use Innmind\TimeContinuum\{ - Clock, - Earth, -}; +use Innmind\TimeContinuum\Clock; use Innmind\Filesystem\{ File, File\Content, @@ -25,7 +22,7 @@ class FactoryTest extends TestCase { public function testBuild() { - $clock = $this->createMock(Clock::class); + $clock = Clock::live(); $os = Factory::build(Config::of()->withClock($clock)); @@ -37,7 +34,7 @@ public function testClockIsOptional() { $os = Factory::build(); - $this->assertInstanceOf(Earth\Clock::class, $os->clock()); + $this->assertInstanceOf(Clock::class, $os->clock()); } public function testPersistingFileOnCaseInsensitiveFilesystem() diff --git a/tests/Filesystem/LoggerTest.php b/tests/Filesystem/LoggerTest.php index b4dde20..41aade7 100644 --- a/tests/Filesystem/LoggerTest.php +++ b/tests/Filesystem/LoggerTest.php @@ -6,9 +6,14 @@ use Innmind\OperatingSystem\{ Filesystem\Logger, Filesystem, + Factory, }; use Innmind\Filesystem\Adapter; -use Innmind\FileWatch\Ping; +use Innmind\{ + FileWatch, + FileWatch\Ping, +}; +use Innmind\TimeWarp\Halt; use Innmind\Immutable\Maybe; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; @@ -105,15 +110,21 @@ public function testWatch() $this ->forAll(Path::any()) ->then(function($path) { + $os = Factory::build(); + $watch = FileWatch\Factory::build( + $os->control()->processes(), + Halt\Usleep::new(), + ); $inner = $this->createMock(Filesystem::class); $inner ->expects($this->once()) ->method('watch') - ->with($path); + ->with($path) + ->willReturn($watch($path)); $logger = $this->createMock(LoggerInterface::class); $filesystem = Logger::psr($inner, $logger); - $this->assertInstanceOf(Ping\Logger::class, $filesystem->watch($path)); + $this->assertInstanceOf(Ping::class, $filesystem->watch($path)); }); } diff --git a/tests/OperatingSystem/LoggerTest.php b/tests/OperatingSystem/LoggerTest.php index c2cb5c2..e4644b4 100644 --- a/tests/OperatingSystem/LoggerTest.php +++ b/tests/OperatingSystem/LoggerTest.php @@ -43,7 +43,7 @@ public function testInterface() public function testClock() { $this->assertInstanceOf( - TimeContinuum\Logger\Clock::class, + TimeContinuum\Clock::class, $this->os->clock(), ); } diff --git a/tests/OperatingSystem/ResilientTest.php b/tests/OperatingSystem/ResilientTest.php index 180443d..8816d58 100644 --- a/tests/OperatingSystem/ResilientTest.php +++ b/tests/OperatingSystem/ResilientTest.php @@ -12,6 +12,7 @@ Sockets, Remote, CurrentProcess, + Factory, }; use Innmind\Server\Status\Server as ServerStatus; use Innmind\Server\Control\Server as ServerControl; @@ -22,7 +23,7 @@ class ResilientTest extends TestCase { public function testInterface() { - $os = Resilient::of($this->createMock(OperatingSystem::class)); + $os = Resilient::of(Factory::build()); $this->assertInstanceOf(OperatingSystem::class, $os); $this->assertInstanceOf(Clock::class, $os->clock()); diff --git a/tests/OperatingSystem/UnixTest.php b/tests/OperatingSystem/UnixTest.php index e86bc73..1e6348f 100644 --- a/tests/OperatingSystem/UnixTest.php +++ b/tests/OperatingSystem/UnixTest.php @@ -22,7 +22,7 @@ class UnixTest extends TestCase { public function testInterface() { - $clock = $this->createMock(Clock::class); + $clock = Clock::live(); $os = Unix::of(Config::of()->withClock($clock)); diff --git a/tests/Ports/LoggerTest.php b/tests/Ports/LoggerTest.php index df96eb6..70ea9ed 100644 --- a/tests/Ports/LoggerTest.php +++ b/tests/Ports/LoggerTest.php @@ -8,9 +8,9 @@ Ports, }; use Innmind\Url\Authority\Port; -use Innmind\Socket\{ +use Innmind\IO\Sockets\{ Internet\Transport, - Server, + Servers\Server, }; use Innmind\IP\{ IPv4, @@ -63,7 +63,7 @@ public function testOpen() ->expects($this->once()) ->method('open') ->with($transport, $ip, Port::of($port)) - ->willReturn($expected = Maybe::just($this->createMock(Server::class))); + ->willReturn($expected = Maybe::just(null /* hack to avoid creating real server */)); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) diff --git a/tests/Ports/UnixTest.php b/tests/Ports/UnixTest.php index b0e0e4f..a9a1a27 100644 --- a/tests/Ports/UnixTest.php +++ b/tests/Ports/UnixTest.php @@ -8,9 +8,9 @@ Ports, Config, }; -use Innmind\Socket\{ +use Innmind\IO\Sockets\{ Internet\Transport, - Server\Internet, + Servers\Server, }; use Innmind\IP\IPv4; use Innmind\Url\Authority\Port; @@ -32,11 +32,11 @@ public function testOpen() IPv4::localhost(), Port::of(1234), )->match( - static fn($server) => $server->unwrap(), + static fn($server) => $server, static fn() => null, ); - $this->assertInstanceOf(Internet::class, $socket); + $this->assertInstanceOf(Server::class, $socket); $socket->close(); } } diff --git a/tests/Remote/GenericTest.php b/tests/Remote/GenericTest.php index 2d735c4..365c479 100644 --- a/tests/Remote/GenericTest.php +++ b/tests/Remote/GenericTest.php @@ -7,6 +7,7 @@ Remote\Generic, Remote, Config, + Factory, }; use Innmind\Server\Control\{ Server, @@ -17,13 +18,13 @@ Url, Authority\Port, }; -use Innmind\Socket\{ +use Innmind\IO\Sockets\{ Internet\Transport, - Client\Internet, - Server\Internet as InternetServer, + Clients\Client, }; use Innmind\IP\IPv4; use Innmind\HttpTransport\Transport as HttpTransport; +use Innmind\Immutable\Attempt; use Formal\AccessLayer\Connection; use PHPUnit\Framework\TestCase; use Innmind\BlackBox\PHPUnit\BlackBox; @@ -59,7 +60,8 @@ public function testSsh() ->method('execute') ->with($this->callback(static function($command): bool { return $command->toString() === "ssh '-p' '42' 'user@my-vps' 'ls'"; - })); + })) + ->willReturn(Attempt::result(null /* hack to avoid creating real process */)); $remoteServer = $remote->ssh(Url::of('ssh://user@my-vps:42/')); @@ -82,7 +84,8 @@ public function testSshWithoutPort() ->method('execute') ->with($this->callback(static function($command): bool { return $command->toString() === "ssh 'user@my-vps' 'ls'"; - })); + })) + ->willReturn(Attempt::result(null /* hack to avoid creating real process */)); $remoteServer = $remote->ssh(Url::of('ssh://user@my-vps/')); @@ -96,17 +99,20 @@ public function testSocket() $this->createMock(Server::class), Config::of(), ); - $server = InternetServer::of(Transport::tcp(), IPv4::localhost(), Port::of(1234))->match( - static fn($server) => $server, - static fn() => null, - ); + $server = Factory::build() + ->ports() + ->open(Transport::tcp(), IPv4::localhost(), Port::of(1234)) + ->match( + static fn($server) => $server, + static fn() => null, + ); $socket = $remote->socket(Transport::tcp(), Url::of('tcp://127.0.0.1:1234')->authority())->match( - static fn($client) => $client->unwrap(), + static fn($client) => $client, static fn() => null, ); - $this->assertInstanceOf(Internet::class, $socket); + $this->assertInstanceOf(Client::class, $socket); $server->close(); $socket->close(); } diff --git a/tests/Remote/LoggerTest.php b/tests/Remote/LoggerTest.php index 6a53132..faca8b6 100644 --- a/tests/Remote/LoggerTest.php +++ b/tests/Remote/LoggerTest.php @@ -9,9 +9,9 @@ }; use Innmind\Server\Control\Servers; use Innmind\HttpTransport\Logger as LoggerTransport; -use Innmind\Socket\{ +use Innmind\IO\Sockets\{ Internet\Transport, - Client, + Clients\Client, }; use Innmind\Url\Url; use Innmind\Immutable\Maybe; @@ -82,7 +82,7 @@ public function testSocket() ->expects($this->once()) ->method('socket') ->with($transport, $authority) - ->willReturn($expected = Maybe::just($this->createMock(Client::class))); + ->willReturn($expected = Maybe::just(null /* hack to avoid creating real client */)); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) diff --git a/tests/Remote/ResilientTest.php b/tests/Remote/ResilientTest.php index 94c1c3b..0dc6634 100644 --- a/tests/Remote/ResilientTest.php +++ b/tests/Remote/ResilientTest.php @@ -10,9 +10,9 @@ }; use Innmind\HttpTransport\ExponentialBackoff; use Innmind\Server\Control\Server; -use Innmind\Socket\{ +use Innmind\IO\Sockets\{ Internet\Transport, - Client, + Clients\Client, }; use Innmind\Immutable\Maybe; use Formal\AccessLayer\Connection; @@ -82,7 +82,7 @@ public function testSocket() ->expects($this->once()) ->method('socket') ->with($transport, $authority) - ->willReturn($expected = Maybe::just($this->createMock(Client::class))); + ->willReturn($expected = Maybe::just(null /* hack to avoid creating real client */)); $this->assertSame($expected, $remote->socket($transport, $authority)); }); diff --git a/tests/Sockets/LoggerTest.php b/tests/Sockets/LoggerTest.php index d675264..05a4e61 100644 --- a/tests/Sockets/LoggerTest.php +++ b/tests/Sockets/LoggerTest.php @@ -7,25 +7,18 @@ Sockets\Logger, Sockets, }; -use Innmind\Socket\{ - Address\Unix as Address, - Server, - Client, +use Innmind\IO\Sockets\{ + Unix\Address, + Servers\Server, + Clients\Client, }; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; -use Innmind\Stream\Watch; +use Innmind\Url\Path; use Innmind\Immutable\Maybe; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; -use Innmind\BlackBox\{ - PHPUnit\BlackBox, - Set, -}; class LoggerTest extends TestCase { - use BlackBox; - public function testInterface() { $this->assertInstanceOf( @@ -39,13 +32,13 @@ public function testInterface() public function testOpen() { - $address = Address::of('/tmp/foo'); + $address = Address::of(Path::of('/tmp/foo')); $inner = $this->createMock(Sockets::class); $inner ->expects($this->once()) ->method('open') ->with($address) - ->willReturn($expected = Maybe::just($this->createMock(Server::class))); + ->willReturn($expected = Maybe::just(null /* hack to avoid creating real server */)); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) @@ -61,13 +54,13 @@ public function testOpen() public function testTakeOver() { - $address = Address::of('/tmp/foo'); + $address = Address::of(Path::of('/tmp/foo')); $inner = $this->createMock(Sockets::class); $inner ->expects($this->once()) ->method('takeOver') ->with($address) - ->willReturn($expected = Maybe::just($this->createMock(Server::class))); + ->willReturn($expected = Maybe::just(null /* hack to avoid creating real server */)); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) @@ -83,13 +76,13 @@ public function testTakeOver() public function testConnectTo() { - $address = Address::of('/tmp/foo'); + $address = Address::of(Path::of('/tmp/foo')); $inner = $this->createMock(Sockets::class); $inner ->expects($this->once()) ->method('connectTo') ->with($address) - ->willReturn($expected = Maybe::just($this->createMock(Client::class))); + ->willReturn($expected = Maybe::just(null /* hack to avoid creating real client */)); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) @@ -102,24 +95,4 @@ public function testConnectTo() $this->assertSame($expected, $sockets->connectTo($address)); } - - public function testWatch() - { - $this - ->forAll(Set\Integers::above(0)) - ->then(function($milliseconds) { - $inner = $this->createMock(Sockets::class); - $inner - ->expects($this->once()) - ->method('watch') - ->with(new ElapsedPeriod($milliseconds)); - $logger = $this->createMock(LoggerInterface::class); - $sockets = Logger::psr($inner, $logger); - - $this->assertInstanceOf( - Watch\Logger::class, - $sockets->watch(new ElapsedPeriod($milliseconds)), - ); - }); - } } diff --git a/tests/Sockets/UnixTest.php b/tests/Sockets/UnixTest.php index 0d14379..5c09655 100644 --- a/tests/Sockets/UnixTest.php +++ b/tests/Sockets/UnixTest.php @@ -8,13 +8,12 @@ Sockets, Config, }; -use Innmind\Socket\{ - Address\Unix as Address, - Server, - Client, +use Innmind\IO\Sockets\{ + Unix\Address, + Servers\Server, + Clients\Client, }; -use Innmind\TimeContinuum\ElapsedPeriod; -use Innmind\Stream\Watch; +use Innmind\Url\Path; use PHPUnit\Framework\TestCase; class UnixTest extends TestCase @@ -28,15 +27,15 @@ public function testOpen() { $sockets = Unix::of(Config::of()); - $socket = $sockets->open(Address::of('/tmp/foo'))->match( - static fn($server) => $server->unwrap(), + $socket = $sockets->open(Address::of(Path::of('/tmp/foo')))->match( + static fn($server) => $server, static fn() => null, ); - $this->assertInstanceOf(Server\Unix::class, $socket); + $this->assertInstanceOf(Server::class, $socket); // return nothing as the socket already exist - $this->assertNull($sockets->open(Address::of('/tmp/foo'))->match( + $this->assertNull($sockets->open(Address::of(Path::of('/tmp/foo')))->match( static fn($server) => $server, static fn() => null, )); @@ -47,16 +46,16 @@ public function testTakeOver() { $sockets = Unix::of(Config::of()); - $socket = $sockets->open(Address::of('/tmp/foo'))->match( - static fn($server) => $server->unwrap(), + $socket = $sockets->open(Address::of(Path::of('/tmp/foo')))->match( + static fn($server) => $server, static fn() => null, ); - $socket2 = $sockets->takeOver(Address::of('/tmp/foo'))->match( - static fn($server) => $server->unwrap(), + $socket2 = $sockets->takeOver(Address::of(Path::of('/tmp/foo')))->match( + static fn($server) => $server, static fn() => null, ); - $this->assertInstanceOf(Server\Unix::class, $socket2); + $this->assertInstanceOf(Server::class, $socket2); $this->assertNotSame($socket, $socket2); $socket2->close(); } @@ -65,27 +64,17 @@ public function testConnectTo() { $sockets = Unix::of(Config::of()); - $server = $sockets->open(Address::of('/tmp/foo'))->match( - static fn($server) => $server->unwrap(), + $server = $sockets->open(Address::of(Path::of('/tmp/foo')))->match( + static fn($server) => $server, static fn() => null, ); - $client = $sockets->connectTo(Address::of('/tmp/foo'))->match( - static fn($client) => $client->unwrap(), + $client = $sockets->connectTo(Address::of(Path::of('/tmp/foo')))->match( + static fn($client) => $client, static fn() => null, ); - $this->assertInstanceOf(Client\Unix::class, $client); + $this->assertInstanceOf(Client::class, $client); $client->close(); $server->close(); } - - public function testWatch() - { - $sockets = Unix::of(Config::of()); - - $this->assertInstanceOf( - Watch::class, - $sockets->watch($this->createMock(ElapsedPeriod::class)), - ); - } }