diff --git a/CHANGELOG.md b/CHANGELOG.md index 161e17b..970a227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Changed + +- Requires `innmind/foundation:~1.5` + ### Fixed - PHP `8.4` deprecations diff --git a/benchmark/client.php b/benchmark/client.php index a09ea36..a5bfd8e 100644 --- a/benchmark/client.php +++ b/benchmark/client.php @@ -7,8 +7,8 @@ Factory, Transport\Connection, }; -use Innmind\Socket\Internet\Transport; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\IO\Sockets\Internet\Transport; +use Innmind\TimeContinuum\Period; use Innmind\Url\Url; use Innmind\OperatingSystem\Factory as OSFactory; @@ -18,6 +18,6 @@ ->make( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), ) ->listenSignals($os->process()); diff --git a/composer.json b/composer.json index 0b93493..bf0177b 100644 --- a/composer.json +++ b/composer.json @@ -16,16 +16,8 @@ }, "require": { "php": "~8.2", - "innmind/immutable": "~5.7", - "innmind/time-continuum": "~3.1", - "innmind/math": "~6.0", - "innmind/url": "~4.1", - "ramsey/uuid": "~4.0", - "innmind/operating-system": "~5.0", - "innmind/media-type": "~2.0", - "innmind/filesystem": "~7.0", - "innmind/stream": "~4.0", - "innmind/io": "~2.6" + "innmind/foundation": "~1.5", + "ramsey/uuid": "~4.0" }, "autoload": { "psr-4": { diff --git a/fixtures/forever-consumer.php b/fixtures/forever-consumer.php index 38b317f..898a0b7 100644 --- a/fixtures/forever-consumer.php +++ b/fixtures/forever-consumer.php @@ -9,8 +9,8 @@ Command\Consume, }; use Innmind\OperatingSystem\Factory as OSFactory; -use Innmind\Socket\Internet\Transport; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\IO\Sockets\Internet\Transport; +use Innmind\TimeContinuum\Period; use Innmind\Url\Url; $os = OSFactory::build(); @@ -18,7 +18,7 @@ ->make( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), ) ->listenSignals($os->process()) ->with(DeclareQueue::of('always-empty')) diff --git a/src/Factory.php b/src/Factory.php index 93049b6..b3b73ec 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP; use Innmind\OperatingSystem\OperatingSystem; -use Innmind\Socket\Internet\Transport as Socket; +use Innmind\IO\Sockets\Internet\Transport as Socket; use Innmind\Url\Url; use Innmind\TimeContinuum\ElapsedPeriod; diff --git a/src/TimeContinuum/Format/Timestamp.php b/src/TimeContinuum/Format/Timestamp.php index e864b5f..ed0e444 100644 --- a/src/TimeContinuum/Format/Timestamp.php +++ b/src/TimeContinuum/Format/Timestamp.php @@ -6,14 +6,15 @@ use Innmind\TimeContinuum\Format; /** - * @psalm-immutable * @internal */ -final class Timestamp implements Format +final class Timestamp { - #[\Override] - public function toString(): string + /** + * @psalm-pure + */ + public static function new(): Format { - return 'U'; + return Format::of('U'); } } diff --git a/src/Transport/Connection.php b/src/Transport/Connection.php index 01f9ef6..ade49dd 100644 --- a/src/Transport/Connection.php +++ b/src/Transport/Connection.php @@ -23,13 +23,10 @@ Exception\FrameExceedAllowedSize, }; use Innmind\OperatingSystem\CurrentProcess\Signals; -use Innmind\Socket\{ - Internet\Transport, - Client as Socket, -}; use Innmind\IO\{ - Sockets\Client, - Readable\Frame as IOFrame, + Sockets\Clients\Client, + Sockets\Internet\Transport, + Frame as IOFrame, }; use Innmind\Url\Url; use Innmind\TimeContinuum\{ @@ -52,7 +49,6 @@ final class Connection { private Protocol $protocol; - /** @var Client */ private Client $socket; /** @var IOFrame */ private IOFrame $frame; @@ -60,9 +56,9 @@ final class Connection private MaxFrameSize $maxFrameSize; private Heartbeat $heartbeat; private SignalListener $signals; + private bool $closed = false; /** - * @param Client $socket * @param IOFrame $frame */ private function __construct( @@ -94,7 +90,6 @@ public static function open( Clock $clock, Remote $remote, ): Maybe { - /** @psalm-suppress InvalidArgument */ return $remote ->socket( $transport, @@ -102,12 +97,12 @@ public static function open( ) ->map( static fn($socket) => $socket - ->timeoutAfter($timeout) + ->timeoutAfter($timeout->asPeriod()) ->toEncoding(Str\Encoding::ascii), ) ->flatMap( static fn($socket) => $socket - ->send(Sequence::of($protocol->version()->pack())) + ->sink(Sequence::of($protocol->version()->pack())) ->map(static fn() => $socket), ) ->map(static fn($socket) => new self( @@ -119,6 +114,7 @@ public static function open( (new FrameReader)($protocol), SignalListener::uninstalled(), )) + ->maybe() ->flatMap(new Start($server->authority())) ->flatMap(new Handshake($server->authority())) ->flatMap(new OpenVHost($server->path())); @@ -199,18 +195,13 @@ public function close(): Maybe { $this->signals->uninstall(); - if ($this->closed()) { - /** @var Maybe */ - return Maybe::nothing(); - } - return $this ->request( static fn($protocol) => $protocol->connection()->close(Close::demand()), Method::connectionCloseOk, ) - ->flatMap(fn() => $this->socket->unwrap()->close()) ->maybe() + ->flatMap(fn() => $this->socket->close()->maybe()) ->map(static fn() => new SideEffect); } @@ -234,7 +225,7 @@ public function tune( ->map(fn() => new self( $this->protocol, $this->heartbeat->adjust($heartbeat), - $this->socket->timeoutAfter($heartbeat), + $this->socket->timeoutAfter($heartbeat->asPeriod()), $maxChannels, $maxFrameSize, $this->frame, @@ -286,7 +277,7 @@ private function sendFrames(callable $frames): Either return $this ->socket ->abortWhen($this->signals->notified(...)) - ->send($data) + ->sink($data) ->either() ->eitherWay( static fn() => Either::right(new SideEffect), @@ -371,9 +362,4 @@ private function ensureValidFrame( /** @var Either */ return Either::left(Failure::unexpectedFrame()); } - - private function closed(): bool - { - return $this->socket->unwrap()->closed(); - } } diff --git a/src/Transport/Connection/FrameReader.php b/src/Transport/Connection/FrameReader.php index 1084b2b..471ed25 100644 --- a/src/Transport/Connection/FrameReader.php +++ b/src/Transport/Connection/FrameReader.php @@ -14,7 +14,7 @@ Frame\Value\UnsignedShortInteger, Frame\Value\UnsignedLongInteger, }; -use Innmind\IO\Readable\Frame as IOFrame; +use Innmind\IO\Frame as IOFrame; use Innmind\Immutable\Str; /** @@ -53,7 +53,7 @@ private function readFrame( Type::method => $this->readMethod($protocol, $channel), Type::header => $this->readHeader($protocol, $channel), Type::body => $this->readBody($channel, $length), - Type::heartbeat => IOFrame\NoOp::of(Frame::heartbeat()), + Type::heartbeat => IOFrame::just(Frame::heartbeat()), }) ->flatMap( static fn($frame) => UnsignedOctet::frame() @@ -119,7 +119,8 @@ private function readHeader( ->map(static fn($value) => $value->unwrap()->original()) ->flatMap(MethodClass::frame(...)) ->flatMap( - static fn($class) => IOFrame\Chunk::of(2) // walk over the weight definition + static fn($class) => IOFrame::chunk(2) // walk over the weight definition + ->strict() ->map(static fn() => $class), ) ->flatMap( @@ -143,8 +144,8 @@ private function readBody( int $length, ): IOFrame { return (match ($length) { - 0 => IOFrame\NoOp::of(Str::of('')), - default => IOFrame\Chunk::of($length), + 0 => IOFrame::just(Str::of('')), + default => IOFrame::chunk($length)->strict(), }) ->map(static fn($data) => Frame::body($channel, $data)); } diff --git a/src/Transport/Connection/Handshake.php b/src/Transport/Connection/Handshake.php index 6beca6a..c7d1297 100644 --- a/src/Transport/Connection/Handshake.php +++ b/src/Transport/Connection/Handshake.php @@ -13,7 +13,7 @@ Model\Connection\MaxFrameSize, Failure, }; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\Period; use Innmind\Url\Authority; use Innmind\Immutable\{ Maybe, @@ -87,7 +87,8 @@ private function maybeTune(Connection $connection, Frame $frame): Either ->get(2) ->keep(Instance::of(Value\UnsignedShortInteger::class)) ->map(static fn($value) => $value->original()) - ->map(ElapsedPeriod::of(...)); + ->map(Period::millisecond(...)) + ->map(static fn($period) => $period->asElapsedPeriod()); return Maybe::all($maxChannels, $maxFrameSize, $heartbeat) ->flatMap($connection->tune(...)) diff --git a/src/Transport/Connection/MessageReader.php b/src/Transport/Connection/MessageReader.php index 9278493..d31b494 100644 --- a/src/Transport/Connection/MessageReader.php +++ b/src/Transport/Connection/MessageReader.php @@ -21,9 +21,10 @@ Failure, }; use Innmind\OperatingSystem\Filesystem; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\Period; use Innmind\Filesystem\File\Content; -use Innmind\Stream\Stream\Size\Unit; +use Innmind\IO\Stream\Size\Unit; +use Innmind\Validation\Is; use Innmind\Immutable\{ Str, Predicate\Instance, @@ -173,8 +174,14 @@ private function addProperties( static fn(Maybe $value, Message $message) => $value ->keep(Instance::of(Value\ShortString::class)) ->map(static fn($value) => (int) $value->original()->toString()) - ->flatMap(ElapsedPeriod::maybe(...)) - ->map(static fn($expiration) => $message->withExpiration($expiration)), + ->keep( + Is::int() + ->positive() + ->or(Is::value(0)) + ->asPredicate(), + ) + ->map(Period::millisecond(...)) + ->map(static fn($expiration) => $message->withExpiration($expiration->asElapsedPeriod())), ], [ 7, @@ -254,7 +261,8 @@ private function readMessage( ->wait() ->maybe() ->flatMap(static fn($received) => $received->frame()->content()) - ->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii)); + ->map(static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii)) + ->attempt(static fn() => new \RuntimeException('Failed to read chunk')); $read += $chunk->match( static fn($chunk) => $chunk->length(), static fn() => 0, @@ -268,20 +276,17 @@ private function readMessage( } }); - /** @psalm-suppress MixedArgumentTypeCoercion Because of the reduce it doesn't understand the type of the Sequence */ + /** @var Sequence */ + $unfolded = Sequence::of(); $content = match (true) { $bodySize <= Unit::megabytes->times(2) => $chunks - ->reduce( - Maybe::just(Sequence::of()), - static fn(Maybe $content, $chunk) => Maybe::all($content, $chunk)->map( - static fn(Sequence $chunks, Str $chunk) => ($chunks)($chunk), - ), - ) + ->sink($unfolded) + ->attempt(static fn($chunks, $chunk) => $chunk->map($chunks)) ->map(Content::ofChunks(...)), default => $this ->filesystem ->temporary($chunks) - ->memoize(), // to prevent using a deferred Maybe that would result in out of order reading the socket + ->memoize(), // to prevent using a deferred Attempt that would result in out of order reading the socket }; return $content diff --git a/src/Transport/Frame/Method.php b/src/Transport/Frame/Method.php index 9b961ca..2509c69 100644 --- a/src/Transport/Frame/Method.php +++ b/src/Transport/Frame/Method.php @@ -15,7 +15,7 @@ Table, }; use Innmind\TimeContinuum\Clock; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Maybe, Sequence, @@ -102,8 +102,8 @@ public static function of(int $class, int $method): self public static function frame(int $class, int $method): Frame { return self::maybe($class, $method)->match( - static fn($self) => Frame\NoOp::of($self), - static fn() => Frame\NoOp::of(self::connectionStart)->filter(static fn() => false), // force fail + static fn($self) => Frame::just($self), + static fn() => Frame::just(self::connectionStart)->filter(static fn() => false), // force fail ); } @@ -319,17 +319,17 @@ public function incomingFrame(Clock $clock): Frame Method::queueUnbindOk, Method::transactionSelectOk, Method::transactionCommitOk, - Method::transactionRollbackOk => Frame\NoOp::of(Sequence::of()), // no arguments + Method::transactionRollbackOk => Frame::just(Sequence::of()), // no arguments Method::basicConsumeOk => ShortString::frame()->map(Sequence::of(...)), // consumer tag Method::basicCancelOk => ShortString::frame()->map(Sequence::of(...)), // consumer tag - Method::basicReturn => Frame\Composite::of( + Method::basicReturn => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), UnsignedShortInteger::frame(), // reply code ShortString::frame(), // reply text ShortString::frame(), // exchange ShortString::frame(), // routing key ), - Method::basicDeliver => Frame\Composite::of( + Method::basicDeliver => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), ShortString::frame(), // consumer tag UnsignedLongLongInteger::frame(), // delivery tag @@ -337,7 +337,7 @@ public function incomingFrame(Clock $clock): Frame ShortString::frame(), // exchange ShortString::frame(), // routing key ), - Method::basicGetOk => Frame\Composite::of( + Method::basicGetOk => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), UnsignedLongLongInteger::frame(), // delivery tag Bits::frame(), // redelivered @@ -349,14 +349,14 @@ public function incomingFrame(Clock $clock): Frame Method::channelOpenOk => LongString::frame()->map(Sequence::of(...)), // reserved Method::channelFlow => Bits::frame()->map(Sequence::of(...)), // active Method::channelFlowOk => Bits::frame()->map(Sequence::of(...)), // active - Method::channelClose => Frame\Composite::of( + Method::channelClose => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), UnsignedShortInteger::frame(), // reply code ShortString::frame(), // reply text UnsignedShortInteger::frame(), // failing class id UnsignedShortInteger::frame(), // failing method id ), - Method::connectionStart => Frame\Composite::of( + Method::connectionStart => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), UnsignedOctet::frame(), // major version UnsignedOctet::frame(), // minor version @@ -365,21 +365,21 @@ public function incomingFrame(Clock $clock): Frame LongString::frame(), // locales ), Method::connectionSecure => LongString::frame()->map(Sequence::of(...)), // challenge - Method::connectionTune => Frame\Composite::of( + Method::connectionTune => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), UnsignedShortInteger::frame(), // max channels UnsignedLongInteger::frame(), // max frame size UnsignedShortInteger::frame(), // heartbeat delay ), Method::connectionOpenOk => ShortString::frame()->map(Sequence::of(...)), // known hosts - Method::connectionClose => Frame\Composite::of( + Method::connectionClose => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), UnsignedShortInteger::frame(), // reply code ShortString::frame(), // reply text UnsignedShortInteger::frame(), // failing class id UnsignedShortInteger::frame(), // failing method id ), - Method::queueDeclareOk => Frame\Composite::of( + Method::queueDeclareOk => Frame::compose( static fn(Unpacked ...$values) => Sequence::of(...$values), ShortString::frame(), // queue UnsignedLongInteger::frame(), // message count diff --git a/src/Transport/Frame/MethodClass.php b/src/Transport/Frame/MethodClass.php index 32dab8e..d2414fb 100644 --- a/src/Transport/Frame/MethodClass.php +++ b/src/Transport/Frame/MethodClass.php @@ -3,7 +3,7 @@ namespace Innmind\AMQP\Transport\Frame; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; /** * @psalm-immutable @@ -27,13 +27,13 @@ public static function frame(int $value): Frame { /** @var Frame */ return match ($value) { - 10 => Frame\NoOp::of(self::connection), - 20 => Frame\NoOp::of(self::channel), - 40 => Frame\NoOp::of(self::exchange), - 50 => Frame\NoOp::of(self::queue), - 60 => Frame\NoOp::of(self::basic), - 90 => Frame\NoOp::of(self::transaction), - default => Frame\NoOp::of(self::basic)->filter(static fn() => false), // force fail + 10 => Frame::just(self::connection), + 20 => Frame::just(self::channel), + 40 => Frame::just(self::exchange), + 50 => Frame::just(self::queue), + 60 => Frame::just(self::basic), + 90 => Frame::just(self::transaction), + default => Frame::just(self::basic)->filter(static fn() => false), // force fail }; } diff --git a/src/Transport/Frame/Type.php b/src/Transport/Frame/Type.php index 61d2700..d52c6b4 100644 --- a/src/Transport/Frame/Type.php +++ b/src/Transport/Frame/Type.php @@ -3,7 +3,7 @@ namespace Innmind\AMQP\Transport\Frame; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; /** * @psalm-immutable @@ -24,11 +24,11 @@ enum Type public static function frame(int $value): Frame { return match ($value) { - 1 => Frame\NoOp::of(self::method), - 2 => Frame\NoOp::of(self::header), - 3 => Frame\NoOp::of(self::body), - 8 => Frame\NoOp::of(self::heartbeat), - default => Frame\NoOp::of(self::heartbeat)->filter(static fn() => false), // force fail + 1 => Frame::just(self::method), + 2 => Frame::just(self::header), + 3 => Frame::just(self::body), + 8 => Frame::just(self::heartbeat), + default => Frame::just(self::heartbeat)->filter(static fn() => false), // force fail }; } diff --git a/src/Transport/Frame/Value/Bits.php b/src/Transport/Frame/Value/Bits.php index c7da077..2ab2473 100644 --- a/src/Transport/Frame/Value/Bits.php +++ b/src/Transport/Frame/Value/Bits.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\AMQP\Transport\Frame\Value; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Sequence, @@ -57,7 +57,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(1) + return Frame::chunk(1) + ->strict() ->map( static fn($chunk) => $chunk ->map(static fn($chunk) => \decbin(\ord($chunk))) diff --git a/src/Transport/Frame/Value/Decimal.php b/src/Transport/Frame/Value/Decimal.php index c274646..bf8ad27 100644 --- a/src/Transport/Frame/Value/Decimal.php +++ b/src/Transport/Frame/Value/Decimal.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\AMQP\Transport\Frame\Value; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\Str; /** diff --git a/src/Transport/Frame/Value/LongString.php b/src/Transport/Frame/Value/LongString.php index 6f3d95b..7d96785 100644 --- a/src/Transport/Frame/Value/LongString.php +++ b/src/Transport/Frame/Value/LongString.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\AMQP\Transport\Frame\Value; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -74,8 +74,8 @@ public static function frame(): Frame { return UnsignedLongInteger::frame()->flatMap( static fn($length) => (match ($length->unwrap()->original()) { - 0 => Frame\NoOp::of(Str::of('')), - default => Frame\Chunk::of($length->unwrap()->original()), + 0 => Frame::just(Str::of('')), + default => Frame::chunk($length->unwrap()->original())->strict(), }) ->map(static fn($string) => new self($string)) ->map(static fn($value) => Unpacked::of( diff --git a/src/Transport/Frame/Value/Sequence.php b/src/Transport/Frame/Value/Sequence.php index 0a60467..a50b476 100644 --- a/src/Transport/Frame/Value/Sequence.php +++ b/src/Transport/Frame/Value/Sequence.php @@ -8,7 +8,7 @@ Protocol\ArgumentTranslator, }; use Innmind\TimeContinuum\Clock; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Sequence as Seq, Monoid\Concat, @@ -72,7 +72,7 @@ public static function frame(Clock $clock): Frame return UnsignedLongInteger::frame()->flatMap( static fn($length) => match ($length->unwrap()->original()) { - 0 => Frame\NoOp::of(Unpacked::of($length->read(), $self)), + 0 => Frame::just(Unpacked::of($length->read(), $self)), default => self::unpackNested( $clock, Unpacked::of($length->read(), $self), @@ -124,7 +124,8 @@ private static function unpackNested( Unpacked $unpacked, int $length, ): Frame { - return Frame\Chunk::of(1) + return Frame::chunk(1) + ->strict() ->flatMap(static fn($chunk) => Symbol::frame($clock, $chunk->toString())) ->map(static fn($value) => Unpacked::of( $unpacked->read() + $value->read() + 1, @@ -136,7 +137,7 @@ private static function unpackNested( $value, $length, ), - false => Frame\NoOp::of($value), + false => Frame::just($value), }); } } diff --git a/src/Transport/Frame/Value/ShortString.php b/src/Transport/Frame/Value/ShortString.php index ed21e89..4e60d34 100644 --- a/src/Transport/Frame/Value/ShortString.php +++ b/src/Transport/Frame/Value/ShortString.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\AMQP\Transport\Frame\Value; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -74,8 +74,8 @@ public static function frame(): Frame { return UnsignedOctet::frame()->flatMap( static fn($length) => (match ($length->unwrap()->original()) { - 0 => Frame\NoOp::of(Str::of('')), - default => Frame\Chunk::of($length->unwrap()->original()), + 0 => Frame::just(Str::of('')), + default => Frame::chunk($length->unwrap()->original())->strict(), }) ->map(static fn($string) => new self($string)) ->map(static fn($value) => Unpacked::of( diff --git a/src/Transport/Frame/Value/SignedLongInteger.php b/src/Transport/Frame/Value/SignedLongInteger.php index c309c15..62e543a 100644 --- a/src/Transport/Frame/Value/SignedLongInteger.php +++ b/src/Transport/Frame/Value/SignedLongInteger.php @@ -9,7 +9,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -69,7 +69,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(4) + return Frame::chunk(4) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/SignedLongLongInteger.php b/src/Transport/Frame/Value/SignedLongLongInteger.php index 73a4c5c..ced5057 100644 --- a/src/Transport/Frame/Value/SignedLongLongInteger.php +++ b/src/Transport/Frame/Value/SignedLongLongInteger.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\AMQP\Transport\Frame\Value; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -54,7 +54,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(8) + return Frame::chunk(8) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/SignedOctet.php b/src/Transport/Frame/Value/SignedOctet.php index 829a1ac..3a53076 100644 --- a/src/Transport/Frame/Value/SignedOctet.php +++ b/src/Transport/Frame/Value/SignedOctet.php @@ -9,7 +9,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -71,7 +71,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(1) + return Frame::chunk(1) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/SignedShortInteger.php b/src/Transport/Frame/Value/SignedShortInteger.php index b7588d7..435ce86 100644 --- a/src/Transport/Frame/Value/SignedShortInteger.php +++ b/src/Transport/Frame/Value/SignedShortInteger.php @@ -9,7 +9,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -69,7 +69,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(2) + return Frame::chunk(2) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/Symbol.php b/src/Transport/Frame/Value/Symbol.php index fe68e05..eacf754 100644 --- a/src/Transport/Frame/Value/Symbol.php +++ b/src/Transport/Frame/Value/Symbol.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\TimeContinuum\Clock; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\Str; /** diff --git a/src/Transport/Frame/Value/Table.php b/src/Transport/Frame/Value/Table.php index 3ee30b6..4a65536 100644 --- a/src/Transport/Frame/Value/Table.php +++ b/src/Transport/Frame/Value/Table.php @@ -8,7 +8,7 @@ Protocol\ArgumentTranslator, }; use Innmind\TimeContinuum\Clock; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Sequence as Seq, @@ -84,7 +84,7 @@ public static function frame(Clock $clock): Frame return UnsignedLongInteger::frame()->flatMap( static fn($length) => match ($length->unwrap()->original()) { - 0 => Frame\NoOp::of(Unpacked::of($length->read(), $self)), + 0 => Frame::just(Unpacked::of($length->read(), $self)), default => self::unpackNested( $clock, Unpacked::of($length->read(), $self), @@ -145,7 +145,8 @@ private static function unpackNested( ): Frame { return ShortString::frame() ->flatMap( - static fn($key) => Frame\Chunk::of(1) + static fn($key) => Frame::chunk(1) + ->strict() ->flatMap(static fn($chunk) => Symbol::frame( $clock, $chunk->toString(), @@ -164,7 +165,7 @@ private static function unpackNested( $value, $length, ), - false => Frame\NoOp::of($value), + false => Frame::just($value), }); } } diff --git a/src/Transport/Frame/Value/Timestamp.php b/src/Transport/Frame/Value/Timestamp.php index b2b9811..89ff54d 100644 --- a/src/Transport/Frame/Value/Timestamp.php +++ b/src/Transport/Frame/Value/Timestamp.php @@ -11,7 +11,7 @@ Clock, PointInTime, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -63,15 +63,15 @@ public static function frame(Clock $clock): Frame { return UnsignedLongLongInteger::frame()->flatMap( static fn($time) => $clock - ->at((string) $time->unwrap()->original(), new TimestampFormat) + ->at((string) $time->unwrap()->original(), TimestampFormat::new()) ->map(static fn($point) => new self($point)) ->map(static fn($value) => Unpacked::of( $time->read(), $value, )) ->match( - static fn($unpacked) => Frame\NoOp::of($unpacked), - static fn() => Frame\NoOp::of(Unpacked::of( + static fn($unpacked) => Frame::just($unpacked), + static fn() => Frame::just(Unpacked::of( 0, new self($clock->now()), ))->filter(static fn() => false), // to force failing since the read time is invalid @@ -96,7 +96,7 @@ public function pack(): Str { /** @psalm-suppress ArgumentTypeCoercion */ return UnsignedLongLongInteger::of( - (int) $this->original->format(new TimestampFormat), + (int) $this->original->format(TimestampFormat::new()), )->pack(); } } diff --git a/src/Transport/Frame/Value/UnsignedLongInteger.php b/src/Transport/Frame/Value/UnsignedLongInteger.php index 5b38c11..e546346 100644 --- a/src/Transport/Frame/Value/UnsignedLongInteger.php +++ b/src/Transport/Frame/Value/UnsignedLongInteger.php @@ -9,7 +9,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -80,7 +80,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(4) + return Frame::chunk(4) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/UnsignedLongLongInteger.php b/src/Transport/Frame/Value/UnsignedLongLongInteger.php index c5879f3..197337a 100644 --- a/src/Transport/Frame/Value/UnsignedLongLongInteger.php +++ b/src/Transport/Frame/Value/UnsignedLongLongInteger.php @@ -10,7 +10,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -81,7 +81,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(8) + return Frame::chunk(8) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/UnsignedOctet.php b/src/Transport/Frame/Value/UnsignedOctet.php index 565aec9..6c5e0aa 100644 --- a/src/Transport/Frame/Value/UnsignedOctet.php +++ b/src/Transport/Frame/Value/UnsignedOctet.php @@ -9,7 +9,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -82,7 +82,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(1) + return Frame::chunk(1) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/UnsignedShortInteger.php b/src/Transport/Frame/Value/UnsignedShortInteger.php index 3f326b0..f64b0fa 100644 --- a/src/Transport/Frame/Value/UnsignedShortInteger.php +++ b/src/Transport/Frame/Value/UnsignedShortInteger.php @@ -9,7 +9,7 @@ DefinitionSet\Set, DefinitionSet\Range, }; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\{ Str, Maybe, @@ -80,7 +80,8 @@ public static function wrap(mixed $value): Either */ public static function frame(): Frame { - return Frame\Chunk::of(2) + return Frame::chunk(2) + ->strict() ->map(static function($chunk) { /** * @psalm-suppress PossiblyInvalidArrayAccess Todo apply a predicate diff --git a/src/Transport/Frame/Value/VoidValue.php b/src/Transport/Frame/Value/VoidValue.php index 9f505df..6b185d9 100644 --- a/src/Transport/Frame/Value/VoidValue.php +++ b/src/Transport/Frame/Value/VoidValue.php @@ -4,7 +4,7 @@ namespace Innmind\AMQP\Transport\Frame\Value; use Innmind\AMQP\Transport\Frame\Value; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\Str; /** @@ -20,7 +20,7 @@ final class VoidValue implements Value */ public static function frame(): Frame { - return Frame\NoOp::of(Unpacked::of(0, new self)); + return Frame::just(Unpacked::of(0, new self)); } #[\Override] diff --git a/src/Transport/Protocol.php b/src/Transport/Protocol.php index 1dc6ba3..456c67f 100644 --- a/src/Transport/Protocol.php +++ b/src/Transport/Protocol.php @@ -22,7 +22,7 @@ Frame\Value, }; use Innmind\TimeContinuum\Clock; -use Innmind\IO\Readable\Frame; +use Innmind\IO\Frame; use Innmind\Immutable\Sequence; /** @@ -147,12 +147,12 @@ private function parseHeader( /** @var Frame> */ return $toChunk->match( - static fn($first, $rest) => Frame\Composite::of( + static fn($first, $rest) => Frame::compose( static fn(Value ...$values) => Sequence::of($bodySize, $flags, ...$values), $first, ...$rest->toList(), ), - static fn() => Frame\NoOp::of(Sequence::of($bodySize, $flags)), + static fn() => Frame::just(Sequence::of($bodySize, $flags)), ); } } diff --git a/src/Transport/Protocol/Basic.php b/src/Transport/Protocol/Basic.php index 4b5739e..e366885 100644 --- a/src/Transport/Protocol/Basic.php +++ b/src/Transport/Protocol/Basic.php @@ -254,7 +254,14 @@ private function serializeProperties(Message $message): array [$flagBits, $properties] = $message->expiration()->match( static fn($expiration) => [ $flagBits | (1 << 8), - ($properties)(ShortString::of(Str::of((string) $expiration->milliseconds()))), + ($properties)(ShortString::of(Str::of((string) ( + $expiration + ->asPeriod() + ->milliseconds() + + $expiration + ->asPeriod() + ->seconds() * 1000 + )))), ], static fn() => [$flagBits, $properties], ); diff --git a/src/Transport/Protocol/Connection.php b/src/Transport/Protocol/Connection.php index 171275a..7a2cf69 100644 --- a/src/Transport/Protocol/Connection.php +++ b/src/Transport/Protocol/Connection.php @@ -97,7 +97,10 @@ public function tuneOk(TuneOk $command): Sequence UnsignedShortInteger::internal($command->maxChannels()), UnsignedLongInteger::internal($command->maxFrameSize()), UnsignedShortInteger::of( - (int) ($command->heartbeat()->milliseconds() / 1000), + $command + ->heartbeat() + ->asPeriod() + ->seconds(), ), )); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 1af02cf..9fa170a 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -24,11 +24,11 @@ TimeContinuum\Format\Timestamp as TimestampFormat, Exception\BasicGetNotCancellable, }; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\OperatingSystem\Factory as OSFactory; -use Innmind\TimeContinuum\Earth\{ - ElapsedPeriod, - Period\Millisecond, +use Innmind\TimeContinuum\{ + Period, + Format, }; use Innmind\Filesystem\Name; use Innmind\Server\Control\Server\{ @@ -68,7 +68,7 @@ public function setUp(): void $this->client = Factory::of($this->os)->make( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), ); } @@ -284,7 +284,7 @@ public function testGetMessageWithAllProperties() ->withPriority(Message\Priority::five) ->withCorrelationId(Message\CorrelationId::of('correlation')) ->withReplyTo(Message\ReplyTo::of('reply')) - ->withExpiration(ElapsedPeriod::of(10000)) + ->withExpiration(Period::second(10)->asElapsedPeriod()) ->withId(Message\Id::of('id')) ->withTimestamp($now = $this->os->clock()->now()) ->withType(Message\Type::of('type')) @@ -372,9 +372,9 @@ public function testGetMessageWithAllProperties() static fn() => null, )); $this->assertSame( - (int) ($ts->milliseconds() / 1000), //timestamp expressed in seconds and not milliseconds + (int) $ts->format(Format::of('U')), // timestamp expressed in seconds and not milliseconds $message->headers()->get('timestamp')->match( - static fn($value) => (int) ($value->milliseconds() / 1000), + static fn($value) => (int) $value->format(Format::of('U')), static fn() => null, ), ); @@ -416,7 +416,7 @@ public function testGetMessageWithAllProperties() static fn() => null, )); $this->assertSame(10000, $message->expiration()->match( - static fn($value) => $value->milliseconds(), + static fn($value) => $value->asPeriod()->seconds() * 1000, static fn() => null, )); $this->assertSame('id', $message->id()->match( @@ -424,9 +424,9 @@ public function testGetMessageWithAllProperties() static fn() => null, )); $this->assertSame( - $now->format(new TimestampFormat), + $now->format(TimestampFormat::new()), $message->timestamp()->match( - static fn($value) => $value->format(new TimestampFormat), + static fn($value) => $value->format(TimestampFormat::new()), static fn() => null, ), ); @@ -466,6 +466,7 @@ public function testPublishContentOfAFile() ->os ->filesystem() ->mount(Path::of(__DIR__.'/')) + ->unwrap() ->get(Name::of(\basename(__FILE__))) ->match( static fn($file) => $file->content(), @@ -735,8 +736,9 @@ public function testSignals($signal) ->withArgument('fixtures/forever-consumer.php') ->withEnvironment('PATH', $_SERVER['PATH']) ->withWorkingDirectory(Path::of(\getcwd())), - ); - $this->os->process()->halt(new Millisecond(100)); + ) + ->unwrap(); + $this->os->process()->halt(Period::millisecond(100)); $this ->os ->control() diff --git a/tests/Model/Basic/MessageTest.php b/tests/Model/Basic/MessageTest.php index cad435d..2da672d 100644 --- a/tests/Model/Basic/MessageTest.php +++ b/tests/Model/Basic/MessageTest.php @@ -16,9 +16,9 @@ Message\Type, Message\UserId, }; -use Innmind\TimeContinuum\Earth\{ - PointInTime\Now, - ElapsedPeriod, +use Innmind\TimeContinuum\{ + PointInTime, + Period, }; use Innmind\Immutable\{ Map, @@ -205,7 +205,7 @@ public function testExpiration() { $message = Message::of(Str::of('')); $message2 = $message->withExpiration( - $expected = new ElapsedPeriod(1000), + $expected = Period::second(1)->asElapsedPeriod(), ); $this->assertInstanceOf(Message::class, $message2); @@ -237,7 +237,7 @@ public function testTimestamp() { $message = Message::of(Str::of('')); $message2 = $message->withTimestamp( - $expected = new Now, + $expected = PointInTime::now(), ); $this->assertInstanceOf(Message::class, $message2); diff --git a/tests/Model/Connection/TuneOkTest.php b/tests/Model/Connection/TuneOkTest.php index 9e6b5c8..2c6768e 100644 --- a/tests/Model/Connection/TuneOkTest.php +++ b/tests/Model/Connection/TuneOkTest.php @@ -8,7 +8,7 @@ MaxChannels, MaxFrameSize, }; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\Period; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\Group; @@ -21,7 +21,7 @@ public function testInterface() $command = TuneOk::of( MaxChannels::of(1), MaxFrameSize::of(10), - $heartbeat = ElapsedPeriod::of(1000), + $heartbeat = Period::second(1)->asElapsedPeriod(), ); $this->assertSame(1, $command->maxChannels()); diff --git a/tests/Transport/Connection/FrameReaderTest.php b/tests/Transport/Connection/FrameReaderTest.php index 0ea5775..8611d1b 100644 --- a/tests/Transport/Connection/FrameReaderTest.php +++ b/tests/Transport/Connection/FrameReaderTest.php @@ -34,13 +34,9 @@ TimeContinuum\Format\Timestamp as TimestampFormat, }; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; -use Innmind\TimeContinuum\Earth\{ - ElapsedPeriod, - PointInTime\Now, +use Innmind\TimeContinuum\{ + Period, + PointInTime, Clock, }; use Innmind\Immutable\{ @@ -56,7 +52,7 @@ class FrameReaderTest extends TestCase public function setUp(): void { - $this->protocol = new Protocol(new Clock, new ArgumentTranslator); + $this->protocol = new Protocol(Clock::live(), new ArgumentTranslator); } #[Group('ci')] @@ -78,9 +74,10 @@ public function testReadCommand() ); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() @@ -111,9 +108,10 @@ public function testReturnNothingWhenFrameEndMarkerInvalid() \fwrite($file, $frame); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() @@ -138,9 +136,10 @@ public function testReturnNothingWhenPayloadTooShort() \fwrite($file, $frame); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() @@ -160,9 +159,10 @@ public function testReturnNothingWhenNoFrameDeteted() \fwrite($file, $content = "AMQP\x00\x00\x09\x01"); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() @@ -194,9 +194,9 @@ public function testReadHeader() ->withPriority(Priority::five) ->withCorrelationId(CorrelationId::of('correlation')) ->withReplyTo(ReplyTo::of('reply')) - ->withExpiration(new ElapsedPeriod(1000)) + ->withExpiration(Period::second(1)->asElapsedPeriod()) ->withId(Id::of('id')) - ->withTimestamp($now = new Now) + ->withTimestamp($now = PointInTime::now()) ->withType(MessageType::of('type')) ->withUserId(UserId::of('guest')) ->withAppId(AppId::of('webcrawler')), @@ -212,9 +212,10 @@ public function testReadHeader() \fwrite($file, $header->pack()->toString()); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() @@ -412,9 +413,9 @@ public function testReadHeader() ), ); $this->assertSame( - $now->format(new TimestampFormat), + $now->format(TimestampFormat::new()), $frame->values()->get(11)->match( - static fn($value) => $value->original()->format(new TimestampFormat), + static fn($value) => $value->original()->format(TimestampFormat::new()), static fn() => null, ), ); @@ -473,9 +474,10 @@ public function testReadBody() )->pack()->toString()); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() @@ -502,9 +504,10 @@ public function testReadHeartbeat() \fwrite($file, Frame::heartbeat()->pack()->toString()); \fseek($file, 0); - $frame = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::of($file)) + $frame = IO::fromAmbientAuthority() + ->streams() + ->acquire($file) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames((new FrameReader)($this->protocol)) ->one() diff --git a/tests/Transport/ConnectionTest.php b/tests/Transport/ConnectionTest.php index c9e77f0..9d1cd55 100644 --- a/tests/Transport/ConnectionTest.php +++ b/tests/Transport/ConnectionTest.php @@ -12,9 +12,9 @@ Transport\Frame\Method, Failure, }; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\Url\Url; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\Period; use Innmind\OperatingSystem\Factory; use Innmind\Immutable\{ Sequence, @@ -34,7 +34,7 @@ public function testInterface() Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), $protocol = new Protocol($os->clock(), new ArgumentTranslator), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), $os->clock(), $os->remote(), $os->sockets(), @@ -76,7 +76,7 @@ public function testClose() Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), $protocol = new Protocol($os->clock(), new ArgumentTranslator), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), $os->clock(), $os->remote(), $os->sockets(), @@ -100,7 +100,7 @@ public function testReturnFailureWhenReceivedFrameIsNotTheExpectedOne() Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), new Protocol($os->clock(), new ArgumentTranslator), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), $os->clock(), $os->remote(), $os->sockets(), @@ -132,7 +132,7 @@ public function testReturnFailureWhenConnectionClosedByServer() Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), $protocol = new Protocol($os->clock(), new ArgumentTranslator), - new ElapsedPeriod(1000), + Period::second(1)->asElapsedPeriod(), $os->clock(), $os->remote(), $os->sockets(), diff --git a/tests/Transport/Frame/Value/BitsTest.php b/tests/Transport/Frame/Value/BitsTest.php index 9ab278e..58ae885 100644 --- a/tests/Transport/Frame/Value/BitsTest.php +++ b/tests/Transport/Frame/Value/BitsTest.php @@ -8,10 +8,6 @@ Value, }; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\{ Sequence, Str, @@ -47,9 +43,14 @@ public function testStringCast($bits, $expected) #[DataProvider('decode')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(Bits::frame()) ->one() diff --git a/tests/Transport/Frame/Value/DecimalTest.php b/tests/Transport/Frame/Value/DecimalTest.php index f37ab89..6314bb9 100644 --- a/tests/Transport/Frame/Value/DecimalTest.php +++ b/tests/Transport/Frame/Value/DecimalTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -47,9 +43,14 @@ public function testStringCast($number, $scale, $expected) #[DataProvider('cases')] public function testFromStream($number, $scale, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(Decimal::frame()) ->one() diff --git a/tests/Transport/Frame/Value/LongStringTest.php b/tests/Transport/Frame/Value/LongStringTest.php index 6494791..67803fa 100644 --- a/tests/Transport/Frame/Value/LongStringTest.php +++ b/tests/Transport/Frame/Value/LongStringTest.php @@ -8,10 +8,6 @@ Value, }; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -43,9 +39,14 @@ public function testStringCast($string, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(LongString::frame()) ->one() diff --git a/tests/Transport/Frame/Value/SequenceTest.php b/tests/Transport/Frame/Value/SequenceTest.php index ac55835..2152873 100644 --- a/tests/Transport/Frame/Value/SequenceTest.php +++ b/tests/Transport/Frame/Value/SequenceTest.php @@ -8,12 +8,8 @@ Transport\Frame\Value\LongString, Transport\Frame\Value, }; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\TimeContinuum\Clock; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\{ Sequence as Seq, Str, @@ -49,11 +45,16 @@ public function testStringCast($expected, $values) #[DataProvider('cases')] public function testFromStream($string, $expected) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) - ->frames(Sequence::frame(new Clock)) + ->frames(Sequence::frame(Clock::live())) ->one() ->match( static fn($value) => $value->unwrap(), diff --git a/tests/Transport/Frame/Value/ShortStringTest.php b/tests/Transport/Frame/Value/ShortStringTest.php index 0855ec0..48f4f06 100644 --- a/tests/Transport/Frame/Value/ShortStringTest.php +++ b/tests/Transport/Frame/Value/ShortStringTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -44,9 +40,14 @@ public function testStringCast($string, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(ShortString::frame()) ->one() diff --git a/tests/Transport/Frame/Value/SignedLongIntegerTest.php b/tests/Transport/Frame/Value/SignedLongIntegerTest.php index 11270bb..fc74480 100644 --- a/tests/Transport/Frame/Value/SignedLongIntegerTest.php +++ b/tests/Transport/Frame/Value/SignedLongIntegerTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -47,9 +43,14 @@ public function testStringCast($int, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(SignedLongInteger::frame()) ->one() diff --git a/tests/Transport/Frame/Value/SignedLongLongIntegerTest.php b/tests/Transport/Frame/Value/SignedLongLongIntegerTest.php index 42a3671..3fcd069 100644 --- a/tests/Transport/Frame/Value/SignedLongLongIntegerTest.php +++ b/tests/Transport/Frame/Value/SignedLongLongIntegerTest.php @@ -8,10 +8,6 @@ Value, }; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -46,9 +42,14 @@ public function testStringCast($int, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(SignedLongLongInteger::frame()) ->one() diff --git a/tests/Transport/Frame/Value/SignedOctetTest.php b/tests/Transport/Frame/Value/SignedOctetTest.php index 7004df2..b96bff0 100644 --- a/tests/Transport/Frame/Value/SignedOctetTest.php +++ b/tests/Transport/Frame/Value/SignedOctetTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -44,9 +40,14 @@ public function testStringCast($expected, $octet) #[DataProvider('cases')] public function testFromStream($string, $expected) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(SignedOctet::frame()) ->one() diff --git a/tests/Transport/Frame/Value/SignedShortIntegerTest.php b/tests/Transport/Frame/Value/SignedShortIntegerTest.php index c174227..4b59ae4 100644 --- a/tests/Transport/Frame/Value/SignedShortIntegerTest.php +++ b/tests/Transport/Frame/Value/SignedShortIntegerTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -47,9 +43,14 @@ public function testStringCast($int, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(SignedShortInteger::frame()) ->one() diff --git a/tests/Transport/Frame/Value/TableTest.php b/tests/Transport/Frame/Value/TableTest.php index 0a1f08e..f9f52f5 100644 --- a/tests/Transport/Frame/Value/TableTest.php +++ b/tests/Transport/Frame/Value/TableTest.php @@ -9,12 +9,8 @@ Transport\Frame\Value\LongString, Transport\Frame\Value, }; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\TimeContinuum\Clock; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\{ Map, Str, @@ -52,11 +48,16 @@ public function testStringCast($expected, $map) #[DataProvider('cases')] public function testFromStream($string, $expected) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) - ->frames(Table::frame(new Clock)) + ->frames(Table::frame(Clock::live())) ->one() ->match( static fn($value) => $value->unwrap(), diff --git a/tests/Transport/Frame/Value/TimestampTest.php b/tests/Transport/Frame/Value/TimestampTest.php index b885a0b..2957a29 100644 --- a/tests/Transport/Frame/Value/TimestampTest.php +++ b/tests/Transport/Frame/Value/TimestampTest.php @@ -8,16 +8,10 @@ Value, }; use Innmind\TimeContinuum\{ - Earth\PointInTime\Now, - Earth\PointInTime\PointInTime, - Earth\Clock, - PointInTime as PointInTimeInterface, + PointInTime, + Clock, }; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\Group; @@ -30,7 +24,7 @@ public function testInterface() { $this->assertInstanceOf( Value::class, - Timestamp::of(new Now), + Timestamp::of(PointInTime::now()), ); } @@ -38,7 +32,7 @@ public function testInterface() #[Group('local')] public function testStringCast() { - $value = Timestamp::of($now = new Now); + $value = Timestamp::of($now = PointInTime::now()); $this->assertSame(\pack('J', \time()), $value->pack()->toString()); $this->assertSame($now, $value->original()); } @@ -47,11 +41,16 @@ public function testStringCast() #[Group('local')] public function testFromStream() { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent(\pack('J', $time = \time()))) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, \pack('J', $time = \time())); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) - ->frames(Timestamp::frame(new Clock)) + ->frames(Timestamp::frame(Clock::live())) ->one() ->match( static fn($value) => $value->unwrap(), @@ -59,10 +58,12 @@ public function testFromStream() ); $this->assertInstanceOf(Timestamp::class, $value); - $this->assertInstanceOf(PointInTimeInterface::class, $value->original()); + $this->assertInstanceOf(PointInTime::class, $value->original()); $this->assertTrue( $value->original()->equals( - new PointInTime(\date(\DateTime::ATOM, $time)), + PointInTime::at(new \DateTimeImmutable( + \date(\DateTime::ATOM, $time), + )), ), ); $this->assertSame(\pack('J', $time), $value->pack()->toString()); diff --git a/tests/Transport/Frame/Value/UnsignedLongIntegerTest.php b/tests/Transport/Frame/Value/UnsignedLongIntegerTest.php index ff888b5..b1ad289 100644 --- a/tests/Transport/Frame/Value/UnsignedLongIntegerTest.php +++ b/tests/Transport/Frame/Value/UnsignedLongIntegerTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -68,9 +64,14 @@ public function testStringCast($int, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(UnsignedLongInteger::frame()) ->one() diff --git a/tests/Transport/Frame/Value/UnsignedLongLongIntegerTest.php b/tests/Transport/Frame/Value/UnsignedLongLongIntegerTest.php index 7a8df60..148ac8a 100644 --- a/tests/Transport/Frame/Value/UnsignedLongLongIntegerTest.php +++ b/tests/Transport/Frame/Value/UnsignedLongLongIntegerTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -57,9 +53,14 @@ public function testStringCast($int, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(UnsignedLongLongInteger::frame()) ->one() diff --git a/tests/Transport/Frame/Value/UnsignedOctetTest.php b/tests/Transport/Frame/Value/UnsignedOctetTest.php index ec6ab71..d465356 100644 --- a/tests/Transport/Frame/Value/UnsignedOctetTest.php +++ b/tests/Transport/Frame/Value/UnsignedOctetTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -47,9 +43,14 @@ public function testStringCast($expected, $octet) #[DataProvider('cases')] public function testFromStream($string, $expected) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(UnsignedOctet::frame()) ->one() diff --git a/tests/Transport/Frame/Value/UnsignedShortIntegerTest.php b/tests/Transport/Frame/Value/UnsignedShortIntegerTest.php index 26cca80..bb63114 100644 --- a/tests/Transport/Frame/Value/UnsignedShortIntegerTest.php +++ b/tests/Transport/Frame/Value/UnsignedShortIntegerTest.php @@ -9,10 +9,6 @@ }; use Innmind\Math\Exception\OutOfDefinitionSet; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\Str; use Innmind\BlackBox\PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{ @@ -47,9 +43,14 @@ public function testStringCast($int, $expected) #[DataProvider('cases')] public function testFromStream($expected, $string) { - $value = IO::of(Select::waitForever(...)) - ->readable() - ->wrap(Stream::ofContent($string)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $string); + \fseek($tmp, 0); + + $value = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames(UnsignedShortInteger::frame()) ->one() diff --git a/tests/Transport/Protocol/ArgumentTranslatorTest.php b/tests/Transport/Protocol/ArgumentTranslatorTest.php index 8a79a94..2ede450 100644 --- a/tests/Transport/Protocol/ArgumentTranslatorTest.php +++ b/tests/Transport/Protocol/ArgumentTranslatorTest.php @@ -17,7 +17,7 @@ PHPUnit\Framework\TestCase, Set, }; -use Fixtures\Innmind\TimeContinuum\Earth\PointInTime; +use Fixtures\Innmind\TimeContinuum\PointInTime; use PHPUnit\Framework\Attributes\Group; class ArgumentTranslatorTest extends TestCase diff --git a/tests/Transport/Protocol/BasicTest.php b/tests/Transport/Protocol/BasicTest.php index 87c1e45..06f2e74 100644 --- a/tests/Transport/Protocol/BasicTest.php +++ b/tests/Transport/Protocol/BasicTest.php @@ -39,9 +39,9 @@ Model\Basic\Message\UserId, Model\Connection\MaxFrameSize, }; -use Innmind\TimeContinuum\Earth\{ - PointInTime\Now, - ElapsedPeriod, +use Innmind\TimeContinuum\{ + PointInTime, + Period, }; use Innmind\Immutable\{ Str, @@ -571,9 +571,9 @@ public function testPublishWithProperties() ->withPriority(Priority::five) ->withCorrelationId(CorrelationId::of('correlation')) ->withReplyTo(ReplyTo::of('reply')) - ->withExpiration(new ElapsedPeriod(1000)) + ->withExpiration(Period::second(1)->asElapsedPeriod()) ->withId(Id::of('id')) - ->withTimestamp($now = new Now) + ->withTimestamp($now = PointInTime::now()) ->withType(MessageType::of('type')) ->withUserId(UserId::of('guest')) ->withAppId(AppId::of('webcrawler')), diff --git a/tests/Transport/Protocol/ConnectionTest.php b/tests/Transport/Protocol/ConnectionTest.php index e182607..791012e 100644 --- a/tests/Transport/Protocol/ConnectionTest.php +++ b/tests/Transport/Protocol/ConnectionTest.php @@ -22,7 +22,7 @@ Model\Connection\MaxChannels, Model\Connection\MaxFrameSize, }; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\Period; use Innmind\Url\{ Authority\UserInformation\User, Authority\UserInformation\Password, @@ -370,7 +370,7 @@ public function testTuneOk() TuneOk::of( MaxChannels::of(1), MaxFrameSize::of(10), - ElapsedPeriod::of(3000), + Period::second(3)->asElapsedPeriod(), ), )->match( static fn($frame) => $frame, diff --git a/tests/Transport/Protocol/ReaderTest.php b/tests/Transport/Protocol/ReaderTest.php index 8f61ab7..655b577 100644 --- a/tests/Transport/Protocol/ReaderTest.php +++ b/tests/Transport/Protocol/ReaderTest.php @@ -14,9 +14,8 @@ Frame\Value\Table, Frame\Value\LongString }; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\TimeContinuum\Clock; use Innmind\IO\IO; -use Innmind\Stream\Readable\Stream; use Innmind\Immutable\{ Str, Sequence, @@ -41,10 +40,15 @@ public function testInvokation($method, $arguments) $args .= $arg->pack()->toString(); } - $stream = IO::of(static fn() => null) - ->readable() - ->wrap(Stream::ofContent($args)) - ->frames($method->incomingFrame(new Clock)) + $tmp = \fopen('php://temp', 'w+'); + \fwrite($tmp, $args); + \fseek($tmp, 0); + + $stream = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() + ->frames($method->incomingFrame(Clock::live())) ->one() ->match( static fn($values) => $values, diff --git a/tests/Transport/ProtocolTest.php b/tests/Transport/ProtocolTest.php index 8f149e1..4dcf2f2 100644 --- a/tests/Transport/ProtocolTest.php +++ b/tests/Transport/ProtocolTest.php @@ -29,16 +29,12 @@ Model\Basic\Message\UserId, Model\Connection\MaxFrameSize, }; -use Innmind\TimeContinuum\Earth\{ - ElapsedPeriod, - PointInTime\Now, +use Innmind\TimeContinuum\{ + Period, + PointInTime, Clock, }; use Innmind\IO\IO; -use Innmind\Stream\{ - Readable\Stream, - Watch\Select, -}; use Innmind\Immutable\{ Str, Map, @@ -53,7 +49,7 @@ class ProtocolTest extends TestCase #[Group('local')] public function testInterface() { - $protocol = new Protocol(new Clock, new ArgumentTranslator); + $protocol = new Protocol(Clock::live(), new ArgumentTranslator); $this->assertInstanceOf(Version::class, $protocol->version()); $this->assertSame("AMQP\x00\x00\x09\x01", $protocol->version()->pack()->toString()); @@ -69,7 +65,7 @@ public function testInterface() #[Group('local')] public function testReadHeader() { - $protocol = new Protocol(new Clock, new ArgumentTranslator); + $protocol = new Protocol(Clock::live(), new ArgumentTranslator); $header = $protocol ->basic() @@ -86,9 +82,9 @@ public function testReadHeader() ->withPriority(Priority::five) ->withCorrelationId(CorrelationId::of('correlation')) ->withReplyTo(ReplyTo::of('reply')) - ->withExpiration(new ElapsedPeriod(1000)) + ->withExpiration(Period::second(1)->asElapsedPeriod()) ->withId(Id::of('id')) - ->withTimestamp($now = new Now) + ->withTimestamp($now = PointInTime::now()) ->withType(Type::of('type')) ->withUserId(UserId::of('guest')) ->withAppId(AppId::of('webcrawler')), @@ -101,19 +97,23 @@ public function testReadHeader() static fn() => null, ); - $values = IO::of(Select::waitForever(...)) - ->readable() - ->wrap( - Stream::ofContent( - \implode( - '', - $header - ->values() - ->map(static fn($v) => $v->pack()->toString()) - ->toList(), - ), - ), - ) + $tmp = \fopen('php://temp', 'w+'); + \fwrite( + $tmp, + \implode( + '', + $header + ->values() + ->map(static fn($v) => $v->pack()->toString()) + ->toList(), + ), + ); + \fseek($tmp, 0); + + $values = IO::fromAmbientAuthority() + ->streams() + ->acquire($tmp) + ->read() ->toEncoding(Str\Encoding::ascii) ->frames($protocol->headerFrame()) ->one()