From 16e17266631bfcf450330d1b3a2da362fd088bdb Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 3 Dec 2023 10:55:59 +0100 Subject: [PATCH] update dependencies --- CHANGELOG.md | 9 +++++ composer.json | 9 +++-- src/Model/Basic/Message.php | 7 +--- src/Transport/Connection/MessageReader.php | 15 +++++-- tests/ClientTest.php | 13 +++++- tests/Transport/ConnectionTest.php | 47 ++++++++++------------ 6 files changed, 61 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 319a40f..2851cdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires `innmind/immutable:~5.2` +- Requires `innmind/operating-system:~4.1` +- Requires `innmind/filesystem:~7.0` +- Requires `innmind/io:~2.3` + ## 4.3.0 - 2023-09-23 ### Added diff --git a/composer.json b/composer.json index f5147d5..318e7dd 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,16 @@ }, "require": { "php": "~8.2", - "innmind/immutable": "~4.15|~5.0", + "innmind/immutable": "~5.2", "innmind/time-continuum": "~3.1", "innmind/math": "~6.0", "innmind/url": "~4.1", "ramsey/uuid": "~4.0", - "innmind/operating-system": "~3.1", + "innmind/operating-system": "~4.1", "innmind/media-type": "~2.0", - "innmind/filesystem": "~5.2|~6.0", - "innmind/stream": "~4.0" + "innmind/filesystem": "~7.0", + "innmind/stream": "~4.0", + "innmind/io": "~2.3" }, "autoload": { "psr-4": { diff --git a/src/Model/Basic/Message.php b/src/Model/Basic/Message.php index a2df055..9b4f9a4 100644 --- a/src/Model/Basic/Message.php +++ b/src/Model/Basic/Message.php @@ -19,10 +19,7 @@ PointInTime, ElapsedPeriod, }; -use Innmind\Filesystem\{ - File\Content, - Chunk, -}; +use Innmind\Filesystem\File\Content; use Innmind\Immutable\{ Map, Str, @@ -122,7 +119,7 @@ public static function of(Str $body): self */ public static function file(Content $content): self { - $chunks = (new Chunk)($content)->map( + $chunks = $content->chunks()->map( static fn($chunk) => $chunk->toEncoding(Str\Encoding::ascii), ); /** @var int<0, max> */ diff --git a/src/Transport/Connection/MessageReader.php b/src/Transport/Connection/MessageReader.php index 1f0f3e4..2e40d4b 100644 --- a/src/Transport/Connection/MessageReader.php +++ b/src/Transport/Connection/MessageReader.php @@ -21,8 +21,12 @@ Transport\Frame\Value, Failure, }; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\{ + Earth, + ElapsedPeriod, +}; use Innmind\Filesystem\File\Content; +use Innmind\IO\IO; use Innmind\Stream\{ Capabilities, Bidirectional, @@ -182,7 +186,7 @@ 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(...)) + ->flatMap(Earth\ElapsedPeriod::maybe(...)) ->map(static fn($expiration) => $message->withExpiration($expiration)), ], [ @@ -266,9 +270,14 @@ private function readMessage( ); } + $io = IO::of(fn(?ElapsedPeriod $timeout) => match ($timeout) { + null => $this->streams->watch()->waitForever(), + default => $this->streams->watch()->timeoutAfter($timeout), + }); + return $read->map(static fn($in) => ReceivedMessage::of( $in[0], - Message::file(Content\OfStream::of($in[1])), + Message::file(Content::io($io->readable()->wrap($in[1]))), )); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index b0bb297..810d127 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -30,7 +30,7 @@ ElapsedPeriod, Period\Millisecond, }; -use Innmind\Filesystem\File\Content; +use Innmind\Filesystem\Name; use Innmind\Server\Control\Server\{ Signal, Command, @@ -444,6 +444,15 @@ public function testGetMessageWithAllProperties() public function testPublishContentOfAFile() { + $file = $this + ->os + ->filesystem() + ->mount(Path::of(__DIR__.'/')) + ->get(Name::of(\basename(__FILE__))) + ->match( + static fn($file) => $file->content(), + fn() => $this->fail(), + ); $result = $this ->client ->with(DeclareExchange::of('foo', Type::direct)) @@ -451,7 +460,7 @@ public function testPublishContentOfAFile() ->with(Bind::of('foo', 'bar')) ->with(Purge::of('bar')) ->with(Qos::of(10)) - ->with(Publish::one(Message::file(Content\AtPath::of(Path::of(__FILE__))))->to('foo')) + ->with(Publish::one(Message::file($file))->to('foo')) ->with( Get::of('bar')->handle(function($state, $message, $continuation, $details) { $this->assertNull($state); diff --git a/tests/Transport/ConnectionTest.php b/tests/Transport/ConnectionTest.php index d76d8ef..e90e3e3 100644 --- a/tests/Transport/ConnectionTest.php +++ b/tests/Transport/ConnectionTest.php @@ -15,15 +15,8 @@ }; use Innmind\Socket\Internet\Transport; use Innmind\Url\Url; -use Innmind\TimeContinuum\Earth\{ - ElapsedPeriod, - Clock, -}; -use Innmind\OperatingSystem\{ - Remote, - Sockets, -}; -use Innmind\Server\Control\Server; +use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\OperatingSystem\Factory; use Innmind\Immutable\{ Sequence, SideEffect, @@ -34,14 +27,15 @@ class ConnectionTest extends TestCase { public function testInterface() { + $os = Factory::build(); $connection = Connection::open( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - $protocol = new Protocol(new Clock, $this->createMock(ArgumentTranslator::class)), + $protocol = new Protocol($os->clock(), $this->createMock(ArgumentTranslator::class)), new ElapsedPeriod(1000), - new Clock, - Remote\Generic::of($this->createMock(Server::class), new Clock), - Sockets\Unix::of(), + $os->clock(), + $os->remote(), + $os->sockets(), )->match( static fn($connection) => $connection, static fn() => null, @@ -74,14 +68,15 @@ public function testInterface() public function testClose() { + $os = Factory::build(); $connection = Connection::open( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - $protocol = new Protocol(new Clock, $this->createMock(ArgumentTranslator::class)), + $protocol = new Protocol($os->clock(), $this->createMock(ArgumentTranslator::class)), new ElapsedPeriod(1000), - new Clock, - Remote\Generic::of($this->createMock(Server::class), new Clock), - Sockets\Unix::of(), + $os->clock(), + $os->remote(), + $os->sockets(), )->match( static fn($connection) => $connection, static fn() => null, @@ -95,14 +90,15 @@ public function testClose() public function testReturnFailureWhenReceivedFrameIsNotTheExpectedOne() { + $os = Factory::build(); $connection = Connection::open( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - new Protocol(new Clock, $this->createMock(ArgumentTranslator::class)), + new Protocol($os->clock(), $this->createMock(ArgumentTranslator::class)), new ElapsedPeriod(1000), - new Clock, - Remote\Generic::of($this->createMock(Server::class), new Clock), - Sockets\Unix::of(), + $os->clock(), + $os->remote(), + $os->sockets(), )->match( static fn($connection) => $connection, static fn() => null, @@ -123,14 +119,15 @@ public function testReturnFailureWhenReceivedFrameIsNotTheExpectedOne() public function testReturnFailureWhenConnectionClosedByServer() { + $os = Factory::build(); $connection = Connection::open( Transport::tcp(), Url::of('//guest:guest@localhost:5672/'), - $protocol = new Protocol(new Clock, $this->createMock(ArgumentTranslator::class)), + $protocol = new Protocol($os->clock(), $this->createMock(ArgumentTranslator::class)), new ElapsedPeriod(1000), - new Clock, - Remote\Generic::of($this->createMock(Server::class), new Clock), - Sockets\Unix::of(), + $os->clock(), + $os->remote(), + $os->sockets(), )->match( static fn($connection) => $connection, static fn() => null,