diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 189105d..779f162 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,13 +4,11 @@ on: [push, pull_request] jobs: blackbox: - uses: innmind/github-workflows/.github/workflows/black-box-matrix.yml@main + uses: innmind/github-workflows/.github/workflows/black-box-matrix.yml@next coverage: - uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@main + uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@next secrets: inherit psalm: - uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main + uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@next cs: - uses: innmind/github-workflows/.github/workflows/cs.yml@main - with: - php-version: '8.2' + uses: innmind/github-workflows/.github/workflows/cs.yml@next diff --git a/CHANGELOG.md b/CHANGELOG.md index a99eec0..4d2e4ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [Unreleased] + +### Added + +- `Innmind\OperatingSystem\Config::useServerControl()` +- `Innmind\OperatingSystem\Config::useServerStatus()` +- `Innmind\OperatingSystem\Config::useFileWatch()` + +### Changed + +- Requires PHP `8.4` +- `Innmind\OperatingSystem\Remote::sql()` now returns an `Innmind\Immutable\Attempt` +- `Innmind\OperatingSystem\Filesystem::mount()` now longer automatically create the directory + ## 6.2.0 - 2025-08-10 ### Added diff --git a/composer.json b/composer.json index 67b02d7..6b185e3 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,23 @@ "issues": "http://github.com/Innmind/OperatingSystem/issues" }, "require": { - "php": "~8.2", - "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": "~4.0", - "innmind/file-watch": "~5.0", - "formal/access-layer": "~4.0", - "innmind/io": "~3.2", - "innmind/immutable": "~5.15" + "php": "~8.4", + "innmind/time-continuum": "dev-next", + "innmind/server-status": "dev-next", + "innmind/server-control": "dev-next", + "innmind/filesystem": "dev-next", + "innmind/http-transport": "dev-next", + "innmind/time-warp": "dev-next", + "innmind/signals": "dev-next", + "innmind/file-watch": "dev-next", + "formal/access-layer": "dev-next", + "innmind/io": "dev-next", + "innmind/immutable": "dev-next", + "innmind/http": "dev-next", + "innmind/media-type": "dev-next", + "innmind/url": "dev-next", + "innmind/validation": "dev-next", + "innmind/ip": "dev-next" }, "autoload": { "psr-4": { @@ -39,8 +44,6 @@ } }, "require-dev": { - "innmind/url": "~4.0", - "innmind/ip": "~3.0", "innmind/static-analysis": "^1.2.1", "innmind/black-box": "~6.2", "innmind/coding-standard": "~2.0" diff --git a/src/Config.php b/src/Config.php index e866fc8..7bfa62a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -3,19 +3,20 @@ namespace Innmind\OperatingSystem; -use Innmind\Server\Control; -use Innmind\Server\Status; -use Innmind\TimeContinuum\Clock; -use Innmind\HttpTransport\{ - Transport as HttpTransport, - Curl, +use Innmind\Server\{ + Control, + Status, + Status\EnvironmentPath, + Status\ServerFactory, }; +use Innmind\TimeContinuum\Clock; +use Innmind\HttpTransport\Transport as HttpTransport; use Innmind\Filesystem\{ Adapter as Filesystem, - CaseSensitivity + CaseSensitivity, + Exception\RecoverMount, }; use Innmind\FileWatch\Watch; -use Innmind\Server\Status\EnvironmentPath; use Innmind\Signals\Handler; use Innmind\TimeWarp\Halt; use Innmind\IO\IO; @@ -34,7 +35,7 @@ final class Config * @param \Closure(Clock, self): Clock $mapClock * @param \Closure(Halt, self): Halt $mapHalt * @param \Closure(HttpTransport, self): HttpTransport $mapHttpTransport - * @param \Closure(Url): AccessLayer\Connection $sql + * @param \Closure(Url): Attempt $sql * @param \Closure(AccessLayer\Connection, self): AccessLayer\Connection $mapSql * @param \Closure(Control\Server, self): Control\Server $mapServerControl * @param \Closure(Status\Server, self): Status\Server $mapServerStatus @@ -53,8 +54,11 @@ private function __construct( private \Closure $mapHttpTransport, private \Closure $sql, private \Closure $mapSql, + private ?Control\Server $serverControl, private \Closure $mapServerControl, + private ?Status\Server $serverStatus, private \Closure $mapServerStatus, + private ?Watch $watch, private \Closure $mapFileWatch, private \Closure $filesystem, private \Closure $mapFilesystem, @@ -69,7 +73,7 @@ public static function new(): self Clock::live(), static fn(Clock $clock) => $clock, IO::fromAmbientAuthority(), - Halt\Usleep::new(), + Halt::new(), static fn(Halt $halt, self $config) => $halt, EnvironmentPath::of(match ($path = \getenv('PATH')) { false => '', @@ -77,18 +81,18 @@ public static function new(): self }), null, static fn(HttpTransport $transport, self $config) => $transport, - static fn(Url $server) => AccessLayer\Connection\Lazy::of( - static fn() => AccessLayer\Connection\PDO::of($server), - ), + static fn(Url $server) => AccessLayer\Connection::new($server), static fn(AccessLayer\Connection $connection, self $config) => $connection, + null, static fn(Control\Server $server, self $config) => $server, + null, static fn(Status\Server $server, self $config) => $server, + null, static fn(Watch $watch, self $config) => $watch, - static fn(Path $path, self $config) => Attempt::of( - static fn() => Filesystem\Filesystem::mount( - $path, - $config->io(), - )->withCaseSensitivity(CaseSensitivity::sensitive), + static fn(Path $path, self $config) => Filesystem::mount( + $path, + CaseSensitivity::sensitive, + $config->io(), ), static fn(Filesystem $filesystem, self $config) => $filesystem, Handler::main(), @@ -124,8 +128,11 @@ public function withClock(Clock $clock): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -157,8 +164,11 @@ public function mapClock(\Closure $map): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -183,8 +193,11 @@ public function haltProcessVia(Halt $halt): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -217,8 +230,11 @@ public function mapHalt(\Closure $map): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -243,8 +259,11 @@ public function withIO(IO $io): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -269,8 +288,11 @@ public function withEnvironmentPath(EnvironmentPath $path): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -295,8 +317,11 @@ public function useHttpTransport(HttpTransport $transport): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -328,8 +353,11 @@ public function mapHttpTransport(\Closure $map): self ), $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -340,7 +368,7 @@ public function mapHttpTransport(\Closure $map): self /** * @psalm-mutation-free * - * @param \Closure(Url): AccessLayer\Connection $sql + * @param \Closure(Url): Attempt $sql */ #[\NoDiscard] public function openSQLConnectionVia(\Closure $sql): self @@ -356,8 +384,11 @@ public function openSQLConnectionVia(\Closure $sql): self $this->mapHttpTransport, $sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -389,8 +420,40 @@ public function mapSQLConnection(\Closure $map): self $previous($connection, $config), $config, ), + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, + $this->mapFileWatch, + $this->filesystem, + $this->mapFilesystem, + $this->signals, + ); + } + + /** + * @psalm-mutation-free + */ + #[\NoDiscard] + public function useServerControl(Control\Server $server): self + { + return new self( + $this->clock, + $this->mapClock, + $this->io, + $this->halt, + $this->mapHalt, + $this->path, + $this->httpTransport, + $this->mapHttpTransport, + $this->sql, + $this->mapSql, + $server, + $this->mapServerControl, + $this->serverStatus, + $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -419,11 +482,43 @@ public function mapServerControl(\Closure $map): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, static fn(Control\Server $server, self $config) => $map( $previous($server, $config), $config, ), + $this->serverStatus, + $this->mapServerStatus, + $this->watch, + $this->mapFileWatch, + $this->filesystem, + $this->mapFilesystem, + $this->signals, + ); + } + + /** + * @psalm-mutation-free + */ + #[\NoDiscard] + public function useServerStatus(Status\Server $server): self + { + return new self( + $this->clock, + $this->mapClock, + $this->io, + $this->halt, + $this->mapHalt, + $this->path, + $this->httpTransport, + $this->mapHttpTransport, + $this->sql, + $this->mapSql, + $this->serverControl, + $this->mapServerControl, + $server, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -452,11 +547,43 @@ public function mapServerStatus(\Closure $map): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, static fn(Status\Server $server, self $config) => $map( $previous($server, $config), $config, ), + $this->watch, + $this->mapFileWatch, + $this->filesystem, + $this->mapFilesystem, + $this->signals, + ); + } + + /** + * @psalm-mutation-free + */ + #[\NoDiscard] + public function useFileWatch(Watch $watch): self + { + return new self( + $this->clock, + $this->mapClock, + $this->io, + $this->halt, + $this->mapHalt, + $this->path, + $this->httpTransport, + $this->mapHttpTransport, + $this->sql, + $this->mapSql, + $this->serverControl, + $this->mapServerControl, + $this->serverStatus, + $this->mapServerStatus, + $watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -485,8 +612,11 @@ public function mapFileWatch(\Closure $map): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, static fn(Watch $watch, self $config) => $map( $previous($watch, $config), $config, @@ -516,8 +646,11 @@ public function mountFilesystemVia(\Closure $filesystem): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $filesystem, $this->mapFilesystem, @@ -546,8 +679,11 @@ public function mapFilesystem(\Closure $map): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, static fn(Filesystem $filesystem, self $config) => $map( @@ -575,8 +711,11 @@ public function handleSignalsVia(Handler $handler): self $this->mapHttpTransport, $this->sql, $this->mapSql, + $this->serverControl, $this->mapServerControl, + $this->serverStatus, $this->mapServerStatus, + $this->watch, $this->mapFileWatch, $this->filesystem, $this->mapFilesystem, @@ -601,9 +740,21 @@ public function clock(): Clock #[\NoDiscard] public function filesystem(Path $path): Attempt { - return ($this->filesystem)($path, $this)->map( - fn($adapter) => ($this->mapFilesystem)($adapter, $this), + $map = fn(Filesystem $adapter): Filesystem => ($this->mapFilesystem)( + $adapter, + $this, ); + + return ($this->filesystem)($path, $this) + ->mapError(static fn($e) => match (true) { + $e instanceof RecoverMount => new RecoverMount( + static fn() => $e + ->recover() + ->map($map), + ), + default => $e, + }) + ->map($map); } /** @@ -639,7 +790,7 @@ public function environmentPath(): EnvironmentPath #[\NoDiscard] public function httpTransport(): HttpTransport { - $transport = $this->httpTransport ?? Curl::of( + $transport = $this->httpTransport ?? HttpTransport::curl( $this->clock, $this->io, ); @@ -649,13 +800,17 @@ public function httpTransport(): HttpTransport /** * @internal + * + * @return Attempt */ #[\NoDiscard] - public function sql(Url $url): AccessLayer\Connection + public function sql(Url $url): Attempt { - return ($this->mapSql)( - ($this->sql)($url), - $this, + $map = $this->mapSql; + $self = $this; + + return ($this->sql)($url)->map( + static fn($connection) => $map($connection, $self), ); } @@ -663,27 +818,44 @@ public function sql(Url $url): AccessLayer\Connection * @internal */ #[\NoDiscard] - public function serverControl(Control\Server $server): Control\Server + public function serverControl(): Control\Server { - return ($this->mapServerControl)($server, $this); + return ($this->mapServerControl)( + $this->serverControl ?? Control\Server::new( + $this->clock, + $this->io, + $this->halt(), + ), + $this, + ); } /** * @internal */ #[\NoDiscard] - public function serverStatus(Status\Server $server): Status\Server + public function serverStatus(Control\Server $server): Status\Server { - return ($this->mapServerStatus)($server, $this); + return ($this->mapServerStatus)( + $this->serverStatus ?? ServerFactory::build( + $this->clock(), + $server, + $this->path, + ), + $this, + ); } /** * @internal */ #[\NoDiscard] - public function fileWatch(Watch $watch): Watch + public function fileWatch(Control\Server\Processes $processes): Watch { - return ($this->mapFileWatch)($watch, $this); + return ($this->mapFileWatch)( + $this->watch ?? Watch::of($processes, $this->halt()), + $this, + ); } /** diff --git a/src/Config/Logger.php b/src/Config/Logger.php index fb7d2a4..f7d388f 100644 --- a/src/Config/Logger.php +++ b/src/Config/Logger.php @@ -9,7 +9,7 @@ use Innmind\TimeContinuum\Clock; use Innmind\FileWatch\Watch; use Innmind\Filesystem\Adapter as Filesystem; -use Innmind\HttpTransport; +use Innmind\HttpTransport\Transport; use Innmind\TimeWarp\Halt; use Formal\AccessLayer\Connection; use Psr\Log\LoggerInterface; @@ -28,23 +28,23 @@ private function __construct( public function __invoke(Config $config): Config { return $config - ->mapHalt(fn($halt) => Halt\Logger::psr( + ->mapHalt(fn($halt) => Halt::logger( $halt, $this->logger, )) - ->mapHttpTransport(fn($transport) => HttpTransport\Logger::psr( + ->mapHttpTransport(fn($transport) => Transport::logger( $transport, $this->logger, )) - ->mapSQLConnection(fn($connection) => Connection\Logger::psr( + ->mapSQLConnection(fn($connection) => Connection::logger( $connection, $this->logger, )) - ->mapServerControl(fn($server) => Control\Servers\Logger::psr( + ->mapServerControl(fn($server) => Control\Server::logger( $server, $this->logger, )) - ->mapServerStatus(fn($server) => Status\Servers\Logger::of( + ->mapServerStatus(fn($server) => Status\Server::logger( $server, $this->logger, )) @@ -53,7 +53,7 @@ public function __invoke(Config $config): Config $watch, $this->logger, )) - ->mapFilesystem(fn($filesystem) => Filesystem\Logger::psr( + ->mapFilesystem(fn($filesystem) => Filesystem::logger( $filesystem, $this->logger, )); diff --git a/src/Config/Resilient.php b/src/Config/Resilient.php index 3f44206..7d2f83d 100644 --- a/src/Config/Resilient.php +++ b/src/Config/Resilient.php @@ -4,7 +4,7 @@ namespace Innmind\OperatingSystem\Config; use Innmind\OperatingSystem\Config; -use Innmind\HttpTransport\ExponentialBackoff; +use Innmind\HttpTransport\Transport; /** * @psalm-immutable @@ -17,7 +17,7 @@ enum Resilient public function __invoke(Config $config): Config { return $config - ->mapHttpTransport(static fn($transport, $config) => ExponentialBackoff::of( + ->mapHttpTransport(static fn($transport, $config) => Transport::exponentialBackoff( $transport, $config->halt(), )); diff --git a/src/Filesystem.php b/src/Filesystem.php index 4454165..aec3826 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -6,12 +6,13 @@ use Innmind\Filesystem\{ Adapter, File\Content, + Directory, + Name, }; use Innmind\Url\Path; use Innmind\Server\Control\Server\Processes; use Innmind\FileWatch\{ Ping, - Factory, Watch, }; use Innmind\Immutable\{ @@ -30,9 +31,7 @@ final class Filesystem private function __construct(Processes $processes, Config $config) { - $this->watch = $config->fileWatch( - Factory::build($processes, $config->halt()), - ); + $this->watch = $config->fileWatch($processes); $this->config = $config; /** @var \WeakMap */ $this->mounted = new \WeakMap; @@ -76,15 +75,28 @@ public function mount(Path $path): Attempt #[\NoDiscard] public function contains(Path $path): bool { - if (!\file_exists($path->toString())) { - return false; - } + $dir = \rtrim(\dirname($path->toString()), '/').'/'; + $name = \basename($path->toString()); - if ($path->directory() && !\is_dir($path->toString())) { - return false; + $exists = $this + ->config + ->filesystem(Path::of($dir)) + ->maybe(); + + // empty when the path === '/' + if ($name !== '') { + $exists = $exists + ->flatMap(static fn($adapter) => $adapter->get(Name::of($name))) + ->filter(static fn($file) => match (true) { + $path->directory() && !($file instanceof Directory) => false, + default => true, + }); } - return true; + return $exists->match( + static fn() => true, + static fn() => false, + ); } /** @@ -93,19 +105,11 @@ public function contains(Path $path): bool #[\NoDiscard] public function require(Path $path): Maybe { - $path = $path->toString(); - - if (!\file_exists($path) || \is_dir($path)) { - /** @var Maybe */ - return Maybe::nothing(); - } - - /** - * @psalm-suppress UnresolvableInclude - * @psalm-suppress MixedArgument - * @var Maybe - */ - return Maybe::just(require $path); + return $this + ->config + ->io() + ->files() + ->require($path); } #[\NoDiscard] diff --git a/src/OperatingSystem.php b/src/OperatingSystem.php index e99877c..1ce26aa 100644 --- a/src/OperatingSystem.php +++ b/src/OperatingSystem.php @@ -3,22 +3,16 @@ namespace Innmind\OperatingSystem; -use Innmind\Server\Status\{ - Server as ServerStatus, - ServerFactory, -}; -use Innmind\Server\Control\{ - Server as ServerControl, - Servers, -}; +use Innmind\Server\Status; +use Innmind\Server\Control; use Innmind\TimeContinuum\Clock; final class OperatingSystem { private Config $config; private ?Filesystem $filesystem = null; - private ?ServerStatus $status = null; - private ?ServerControl $control = null; + private ?Status\Server $status = null; + private ?Control\Server $control = null; private ?Ports $ports = null; private ?Sockets $sockets = null; private ?Remote $remote = null; @@ -63,27 +57,17 @@ public function filesystem(): Filesystem } #[\NoDiscard] - public function status(): ServerStatus + public function status(): Status\Server { return $this->status ??= $this->config->serverStatus( - ServerFactory::build( - $this->clock(), - $this->control(), - $this->config->environmentPath(), - ), + $this->control(), ); } #[\NoDiscard] - public function control(): ServerControl + public function control(): Control\Server { - return $this->control ??= $this->config->serverControl( - Servers\Unix::of( - $this->clock(), - $this->config->io(), - $this->config->halt(), - ), - ); + return $this->control ??= $this->config->serverControl(); } #[\NoDiscard] diff --git a/src/Remote.php b/src/Remote.php index fee3f57..b81a88a 100644 --- a/src/Remote.php +++ b/src/Remote.php @@ -3,10 +3,7 @@ namespace Innmind\OperatingSystem; -use Innmind\Server\Control\{ - Server, - Servers, -}; +use Innmind\Server\Control\Server; use Innmind\IO\{ Sockets\Clients\Client, Sockets\Internet\Transport, @@ -50,13 +47,11 @@ public function ssh(Url $server): Server $port = $server->authority()->port(); } - return $this->config->serverControl( - Servers\Remote::of( - $this->server, - $server->authority()->userInformation()->user(), - $server->authority()->host(), - $port, - ), + return Server::remote( + $this->server, + $server->authority()->userInformation()->user(), + $server->authority()->host(), + $port, ); } @@ -80,8 +75,11 @@ public function http(): HttpTransport return $this->http ??= $this->config->httpTransport(); } + /** + * @return Attempt + */ #[\NoDiscard] - public function sql(Url $server): Connection + public function sql(Url $server): Attempt { return $this->config->sql($server); } diff --git a/tests/CurrentProcessTest.php b/tests/CurrentProcessTest.php index ca7b1a3..ba3eef6 100644 --- a/tests/CurrentProcessTest.php +++ b/tests/CurrentProcessTest.php @@ -33,7 +33,7 @@ class CurrentProcessTest extends TestCase public function testId() { $process = CurrentProcess::of( - Halt\Usleep::new(), + Halt::new(), Handler::main(), ); @@ -66,7 +66,7 @@ public function testHalt(): BlackBox\Proof public function testSignals() { $process = CurrentProcess::of( - Halt\Usleep::new(), + Halt::new(), Handler::main(), ); @@ -101,7 +101,7 @@ public function testAsyncSignals(): BlackBox\Proof public function testMemory() { $process = CurrentProcess::of( - Halt\Usleep::new(), + Halt::new(), Handler::main(), ); diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 1df7a75..bc1cf2b 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -10,14 +10,14 @@ }; use Innmind\TimeContinuum\Clock; use Innmind\Filesystem\{ - Adapter\Filesystem, + Adapter, File, File\Content, Directory, CaseSensitivity, + Recover, }; use Innmind\Url\Path; -use Innmind\Immutable\Attempt; use Symfony\Component\Filesystem\Filesystem as FS; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -53,17 +53,17 @@ public function testPersistingFileOnCaseInsensitiveFilesystem() $os = Factory::build( Config::new()->mountFilesystemVia( - static fn($path, $config) => Attempt::of( - static fn() => Filesystem::mount( - $path, - $config->io(), - )->withCaseSensitivity(CaseSensitivity::insensitive), + static fn($path, $config) => Adapter::mount( + $path, + CaseSensitivity::insensitive, + $config->io(), ), ), ); $adapter = $os ->filesystem() ->mount(Path::of($path)) + ->recover(Recover::mount(...)) ->unwrap(); $adapter->add( $directory = Directory::named('0') diff --git a/tests/FilesystemTest.php b/tests/FilesystemTest.php index b852d3c..dad311c 100644 --- a/tests/FilesystemTest.php +++ b/tests/FilesystemTest.php @@ -9,7 +9,7 @@ Factory, }; use Innmind\Filesystem\{ - Adapter\Filesystem as FilesystemAdapter, + Adapter, File\Content, }; use Innmind\Url\Path; @@ -40,7 +40,7 @@ public function testMount() $adapter = $filesystem->mount(Path::of('/tmp/'))->unwrap(); - $this->assertInstanceOf(FilesystemAdapter::class, $adapter); + $this->assertInstanceOf(Adapter::class, $adapter); } public function testMountingTheSamePathTwiceReturnsTheSameAdapter() @@ -79,6 +79,9 @@ public function testContainsDirectory() \mkdir('/tmp/some-dir/'); $this->assertTrue($filesystem->contains(Path::of('/tmp/some-dir/'))); \rmdir('/tmp/some-dir/'); + \file_put_contents('/tmp/foo', 'data'); + $this->assertFalse($filesystem->contains(Path::of('/tmp/foo/'))); + \unlink('/tmp/foo'); } public function testWatch() diff --git a/tests/Remote/ResilientTest.php b/tests/Remote/ResilientTest.php index 6a9f805..1712794 100644 --- a/tests/Remote/ResilientTest.php +++ b/tests/Remote/ResilientTest.php @@ -7,7 +7,7 @@ Config, Factory, }; -use Innmind\HttpTransport\ExponentialBackoff; +use Innmind\HttpTransport\Transport; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class ResilientTest extends TestCase @@ -25,6 +25,6 @@ public function testHttp() Config\Resilient::new(), ); - $this->assertInstanceOf(ExponentialBackoff::class, $os->remote()->http()); + $this->assertInstanceOf(Transport::class, $os->remote()->http()); } } diff --git a/tests/RemoteTest.php b/tests/RemoteTest.php index c9a5d1d..d42e92c 100644 --- a/tests/RemoteTest.php +++ b/tests/RemoteTest.php @@ -11,12 +11,7 @@ }; use Innmind\Server\Control\{ Server, - Servers, - Server\Processes, - Server\Volumes, Server\Command, - Server\Process\Pid, - Server\Signal, }; use Innmind\Url\{ Url, @@ -29,7 +24,6 @@ use Innmind\IP\IPv4; use Innmind\HttpTransport\Transport as HttpTransport; use Innmind\Immutable\Attempt; -use Formal\AccessLayer\Connection; use Innmind\BlackBox\{ PHPUnit\BlackBox, PHPUnit\Framework\TestCase, @@ -51,8 +45,8 @@ public function testSsh() $remoteServer = $remote->ssh(Url::of('ssh://user@my-vps:42/')); - $this->assertInstanceOf(Servers\Remote::class, $remoteServer); - $remoteServer + $this->assertInstanceOf(Server::class, $remoteServer); + $_ = $remoteServer ->processes() ->execute(Command::foreground('ls')) ->unwrap(); @@ -67,8 +61,8 @@ public function testSshLogger() $remoteServer = $remote->ssh(Url::of('ssh://user@my-vps:42/')); - $this->assertInstanceOf(Servers\Logger::class, $remoteServer); - $remoteServer + $this->assertInstanceOf(Server::class, $remoteServer); + $_ = $remoteServer ->processes() ->execute(Command::foreground('ls')) ->unwrap(); @@ -83,8 +77,11 @@ public function testSshWithoutPort() $remoteServer = $remote->ssh(Url::of('ssh://user@my-vps/')); - $this->assertInstanceOf(Servers\Remote::class, $remoteServer); - $remoteServer->processes()->execute(Command::foreground('ls')); + $this->assertInstanceOf(Server::class, $remoteServer); + $_ = $remoteServer + ->processes() + ->execute(Command::foreground('ls')) + ->unwrap(); } public function testSocket() @@ -140,66 +137,23 @@ public function testSql(): BlackBox\Proof ->prove(function($server, $os) { $sql = $os->remote()->sql($server); - $this->assertInstanceOf(Connection::class, $sql); + $this->assertInstanceOf(Attempt::class, $sql); }); } private function server(string ...$commands): Server { - return new class($this->processes(), $this, $commands) implements Server { - private $inner; - - public function __construct( - private $processes, - private $test, - private $commands, - ) { - } - - public function processes(): Processes - { - return $this->inner ??= new class($this->processes, $this->test, $this->commands) implements Processes { - public function __construct( - private $processes, - private $test, - private $commands, - ) { - } - - public function execute(Command $command): Attempt - { - $expected = \array_shift($this->commands); - $this->test->assertNotNull($expected); - $this->test->assertSame( - $expected, - $command->toString(), - ); - - return $this->processes->execute(Command::foreground('echo')); - } - - public function kill(Pid $pid, Signal $signal): Attempt - { - } - }; - } - - public function volumes(): Volumes - { - } - - public function reboot(): Attempt - { - } - - public function shutdown(): Attempt - { - } - }; - } + $processes = Factory::build()->control()->processes(); + + return Server::via(function($command) use (&$commands, $processes) { + $expected = \array_shift($commands); + $this->assertNotNull($expected); + $this->assertSame( + $expected, + $command->toString(), + ); - private function processes(): Processes - { - return Factory::build()->control()->processes(); + return $processes->execute(Command::foreground('echo')); + }); } }