From 18514541cac9d1528f7242f1798ad7a92f07e048 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 11 Feb 2023 13:45:10 +0100 Subject: [PATCH] add functional test --- tests/HaltTest.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/HaltTest.php b/tests/HaltTest.php index af26d52..8ed3144 100644 --- a/tests/HaltTest.php +++ b/tests/HaltTest.php @@ -5,6 +5,8 @@ use Innmind\Async\TimeWarp\Halt; use Innmind\Mantle\{ + Forerunner, + Source\Predetermined, Suspend, Suspend\Synchronous, }; @@ -29,4 +31,33 @@ public function testSuspend() $this->assertGreaterThanOrEqual(2, \microtime(true) - $start); } + + public function testFunctional() + { + $queue = new \SplQueue; + $clock = new Clock; + $source = Predetermined::of( + static function(Suspend $suspend) use ($clock, $queue) { + $halt = Halt::of($clock, $suspend); + + $halt(new Second(2)); + + $queue->push('World !'); + }, + static function(Suspend $suspend) use ($clock, $queue) { + $halt = Halt::of($clock, $suspend); + + $halt(new Second(1)); + + $queue->push('Hello '); + }, + ); + + Forerunner::of($clock)(null, $source); + + $this->assertSame( + ['Hello ', 'World !'], + \iterator_to_array($queue), + ); + } }