From 4b2132116bcb9bf3d9e44b9fce89e3f3ec25ee87 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 25 Jul 2024 14:04:05 +0200 Subject: [PATCH] =?UTF-8?q?suppression=20m=C3=A9thode=20uniquement=20utili?= =?UTF-8?q?s=C3=A9e=20dans=20les=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Server/Process/Started.php | 21 ------------- tests/Server/Process/UnixTest.php | 52 +++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/Server/Process/Started.php b/src/Server/Process/Started.php index 7739637..eac00e5 100644 --- a/src/Server/Process/Started.php +++ b/src/Server/Process/Started.php @@ -32,7 +32,6 @@ Either, SideEffect, Set, - Predicate\Instance, }; /** @@ -119,26 +118,6 @@ public function pid(): Pid return $this->pid; } - /** - * @return Either - */ - public function wait(): Either - { - // we don't need to keep the output read while writing to the input - // stream as this data will never be exposed to caller, so by discarding - // this data we prevent ourself from reaching a possible "out of memory" - // error - /** @var Either */ - return $this - ->output() - ->last() - ->keep(Instance::of(Either::class)) - ->match( - static fn($return) => $return, - static fn() => throw new RuntimeException('Unable to retrieve process result'), - ); - } - /** * @return Sequence> */ diff --git a/tests/Server/Process/UnixTest.php b/tests/Server/Process/UnixTest.php index f953f60..df2e562 100644 --- a/tests/Server/Process/UnixTest.php +++ b/tests/Server/Process/UnixTest.php @@ -167,10 +167,15 @@ public function testTimeoutWaitSlowProcess() $started = \microtime(true); $this->assertGreaterThanOrEqual(2, $process->pid()->toInt()); - $e = $process->wait()->match( - static fn() => null, - static fn($e) => $e, - ); + $e = $process + ->output() + ->last() + ->either() + ->flatMap(static fn($result) => $result) + ->match( + static fn() => null, + static fn($e) => $e, + ); $this->assertSame('timed-out', $e); // 3 because of the grace period $this->assertEqualsWithDelta(3, \microtime(true) - $started, 0.5); @@ -186,10 +191,15 @@ public function testWaitSuccess() Command::foreground('echo')->withArgument('hello'), ); - $value = $cat()->wait()->match( - static fn($value) => $value, - static fn() => null, - ); + $value = $cat() + ->output() + ->last() + ->either() + ->flatMap(static fn($result) => $result) + ->match( + static fn($value) => $value, + static fn() => null, + ); $this->assertInstanceOf(SideEffect::class, $value); } @@ -206,10 +216,15 @@ public function testWaitFail() ->withEnvironment('PATH', $_SERVER['PATH']), ); - $value = $cat()->wait()->match( - static fn() => null, - static fn($e) => $e, - ); + $value = $cat() + ->output() + ->last() + ->either() + ->flatMap(static fn($result) => $result) + ->match( + static fn() => null, + static fn($e) => $e, + ); $this->assertInstanceOf(ExitCode::class, $value); $this->assertSame(1, $value->toInt()); @@ -257,10 +272,15 @@ public function testOverwrite() ->overwrite(Path::of('test.log')), ); - $value = $cat()->wait()->match( - static fn($value) => $value, - static fn() => null, - ); + $value = $cat() + ->output() + ->last() + ->either() + ->flatMap(static fn($result) => $result) + ->match( + static fn($value) => $value, + static fn() => null, + ); $this->assertInstanceOf(SideEffect::class, $value); $this->assertSame(