From fa23fb00a8aaa219129edcb18fa84447224a86e5 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 22 Feb 2026 14:06:05 +0100 Subject: [PATCH] update dependencies --- .github/workflows/ci.yml | 2 - CHANGELOG.md | 7 + composer.json | 6 +- src/Control/Permissions.php | 4 +- src/Control/Users.php | 4 +- src/Control/VHosts.php | 4 +- src/Model/Channel.php | 8 +- src/Model/Connection.php | 8 +- src/Model/Queue.php | 8 +- src/Status.php | 22 +- tests/Control/PermissionsTest.php | 80 ++-- tests/Control/UsersTest.php | 80 ++-- tests/Control/VHostsTest.php | 80 ++-- tests/ControlTest.php | 4 +- tests/Model/ChannelTest.php | 4 +- tests/Model/ConnectionTest.php | 4 +- tests/Model/Node/NameTest.php | 2 +- tests/Model/QueueTest.php | 4 +- tests/StatusTest.php | 664 +++++++++++++++++++----------- 19 files changed, 632 insertions(+), 363 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 189105d..2f3eecb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,5 +12,3 @@ jobs: uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: uses: innmind/github-workflows/.github/workflows/cs.yml@main - with: - php-version: '8.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4439ba2..18de6ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.4` +- Requires `innmind/foundation:~2.1` + ## 4.0.0 - 2025-08-09 ### Changed diff --git a/composer.json b/composer.json index 5c2833f..fac3482 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "issues": "http://github.com/Innmind/RabbitMQManagement/issues" }, "require": { - "php": "~8.2", - "innmind/foundation": "^1.7.1" + "php": "~8.4", + "innmind/foundation": "~2.1" }, "autoload": { "psr-4": { @@ -29,7 +29,7 @@ }, "require-dev": { "innmind/black-box": "~6.5", - "innmind/static-analysis": "^1.2.1", + "innmind/static-analysis": "~1.3", "innmind/coding-standard": "~2.0" } } diff --git a/src/Control/Permissions.php b/src/Control/Permissions.php index 700d43d..6c7be33 100644 --- a/src/Control/Permissions.php +++ b/src/Control/Permissions.php @@ -54,7 +54,7 @@ public function declare( ->flatMap(static fn($process) => $process->wait()->attempt( static fn($error) => new \RuntimeException($error::class), )) - ->map(static fn() => new SideEffect); + ->map(SideEffect::identity(...)); } /** @@ -77,6 +77,6 @@ public function delete(string $vhost, string $user): Attempt ->flatMap(static fn($process) => $process->wait()->attempt( static fn($error) => new \RuntimeException($error::class), )) - ->map(static fn() => new SideEffect); + ->map(SideEffect::identity(...)); } } diff --git a/src/Control/Users.php b/src/Control/Users.php index c674c32..87d2a1d 100644 --- a/src/Control/Users.php +++ b/src/Control/Users.php @@ -47,7 +47,7 @@ public function declare(string $name, string $password, string ...$tags): Attemp ->flatMap(static fn($process) => $process->wait()->attempt( static fn($error) => new \RuntimeException($error::class), )) - ->map(static fn() => new SideEffect); + ->map(SideEffect::identity(...)); } /** @@ -69,6 +69,6 @@ public function delete(string $name): Attempt ->flatMap(static fn($process) => $process->wait()->attempt( static fn($error) => new \RuntimeException($error::class), )) - ->map(static fn() => new SideEffect); + ->map(SideEffect::identity(...)); } } diff --git a/src/Control/VHosts.php b/src/Control/VHosts.php index 3f6e5c9..03ab219 100644 --- a/src/Control/VHosts.php +++ b/src/Control/VHosts.php @@ -45,7 +45,7 @@ public function declare(string $name): Attempt ->flatMap(static fn($process) => $process->wait()->attempt( static fn($error) => new \RuntimeException($error::class), )) - ->map(static fn() => new SideEffect); + ->map(SideEffect::identity(...)); } /** @@ -67,6 +67,6 @@ public function delete(string $name): Attempt ->flatMap(static fn($process) => $process->wait()->attempt( static fn($error) => new \RuntimeException($error::class), )) - ->map(static fn() => new SideEffect); + ->map(SideEffect::identity(...)); } } diff --git a/src/Model/Channel.php b/src/Model/Channel.php index 1907480..2aaa80e 100644 --- a/src/Model/Channel.php +++ b/src/Model/Channel.php @@ -7,7 +7,7 @@ Channel\Name, Channel\Messages, }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Immutable\Maybe; /** @@ -16,7 +16,7 @@ final class Channel { /** - * @param Maybe $idleSince + * @param Maybe $idleSince */ private function __construct( private Name $name, @@ -36,7 +36,7 @@ private function __construct( /** * @psalm-pure * - * @param Maybe $idleSince + * @param Maybe $idleSince */ #[\NoDiscard] public static function of( @@ -128,7 +128,7 @@ public function transactional(): bool } /** - * @return Maybe + * @return Maybe */ #[\NoDiscard] public function idleSince(): Maybe diff --git a/src/Model/Connection.php b/src/Model/Connection.php index 0f172cc..b8ed097 100644 --- a/src/Model/Connection.php +++ b/src/Model/Connection.php @@ -11,7 +11,7 @@ Connection\AuthenticationMechanism, Connection\Type, }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Url\Authority\{ Host, Port, @@ -24,7 +24,7 @@ final class Connection { private function __construct( private Name $name, - private PointInTime $connectedAt, + private Point $connectedAt, private Timeout $timeout, private VHost\Name $vhost, private User\Name $user, @@ -46,7 +46,7 @@ private function __construct( #[\NoDiscard] public static function of( Name $name, - PointInTime $connectedAt, + Point $connectedAt, Timeout $timeout, VHost\Name $vhost, User\Name $user, @@ -85,7 +85,7 @@ public function name(): Name } #[\NoDiscard] - public function connectedAt(): PointInTime + public function connectedAt(): Point { return $this->connectedAt; } diff --git a/src/Model/Queue.php b/src/Model/Queue.php index 522d3b8..57a0ffb 100644 --- a/src/Model/Queue.php +++ b/src/Model/Queue.php @@ -7,7 +7,7 @@ Queue\Identity, Queue\Messages, }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Immutable\Maybe; /** @@ -16,7 +16,7 @@ final class Queue { /** - * @param Maybe $idleSince + * @param Maybe $idleSince */ private function __construct( private Identity $identity, @@ -34,7 +34,7 @@ private function __construct( /** * @psalm-pure * - * @param Maybe $idleSince + * @param Maybe $idleSince */ #[\NoDiscard] public static function of( @@ -74,7 +74,7 @@ public function messages(): Messages } /** - * @return Maybe + * @return Maybe */ #[\NoDiscard] public function idleSince(): Maybe diff --git a/src/Status.php b/src/Status.php index fdfdf5a..557b410 100644 --- a/src/Status.php +++ b/src/Status.php @@ -27,7 +27,7 @@ Server, Server\Command, }; -use Innmind\TimeContinuum\{ +use Innmind\Time\{ Clock, Format, }; @@ -177,10 +177,10 @@ public function connections(): Sequence Is::int() ->map(static fn($value) => (string) (int) ($value / 1000)) ->map( - $this + fn($date) => $this ->clock - ->ofFormat(Format::of('U')) - ->at(...), + ->at($date, Format::of('U')) + ->maybe(), ) ->and(Is::just()), ) @@ -450,10 +450,10 @@ public function channels(): Sequence Is::string() ->nonEmpty() ->map( - $this + fn($date) => $this ->clock - ->ofFormat(Format::of('Y-m-d G:i:s')) - ->at(...), + ->at($date, Format::of('Y-m-d G:i:s')) + ->maybe(), ), ) ->default('idle_since', Maybe::nothing()) @@ -581,10 +581,10 @@ public function queues(): Sequence Is::string() ->nonEmpty() ->map( - $this + fn($date) => $this ->clock - ->ofFormat(Format::of('Y-m-d G:i:s')) - ->at(...), + ->at($date, Format::of('Y-m-d G:i:s')) + ->maybe(), ), ) ->default('idle_since', Maybe::nothing()) @@ -694,7 +694,7 @@ private function list(string $element): Sequence static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat) + ->fold(Concat::monoid) ->toString(), ) ->map(static fn($output): mixed => \json_decode($output, true)) diff --git a/tests/Control/PermissionsTest.php b/tests/Control/PermissionsTest.php index ffe13da..3d14cbb 100644 --- a/tests/Control/PermissionsTest.php +++ b/tests/Control/PermissionsTest.php @@ -4,19 +4,32 @@ namespace Tests\Innmind\RabbitMQ\Management\Control; use Innmind\RabbitMQ\Management\Control\Permissions; -use Innmind\Server\Control\Servers\Mock; -use Innmind\Immutable\SideEffect; +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, +}; +use Innmind\Immutable\{ + Attempt, + SideEffect, +}; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class PermissionsTest extends TestCase { public function testDeclare() { - $server = Mock::new($this->assert()) - ->willExecute(fn($command) => $this->assertSame( - "rabbitmqadmin 'declare' 'permission' 'vhost=/' 'user=foo' 'configure=.{1}' 'write=.{2}' 'read=.{3}'", - $command->toString(), - )); + $server = Server::via( + function($command) { + $this->assertSame( + "rabbitmqadmin 'declare' 'permission' 'vhost=/' 'user=foo' 'configure=.{1}' 'write=.{2}' 'read=.{3}'", + $command->toString(), + ); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $permissions = Permissions::of($server); $this->assertInstanceOf( @@ -30,14 +43,20 @@ public function testDeclare() public function testReturnNothingWhenFailToDeclare() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin 'declare' 'permission' 'vhost=/' 'user=foo' 'configure=.{1}' 'write=.{2}' 'read=.{3}'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $permissions = Permissions::of($server); $this->assertNull($permissions->declare('/', 'foo', '.{1}', '.{2}', '.{3}')->match( @@ -48,11 +67,18 @@ public function testReturnNothingWhenFailToDeclare() public function testDelete() { - $server = Mock::new($this->assert()) - ->willExecute(fn($command) => $this->assertSame( - "rabbitmqadmin 'delete' 'permission' 'vhost=/' 'user=foo'", - $command->toString(), - )); + $server = Server::via( + function($command) { + $this->assertSame( + "rabbitmqadmin 'delete' 'permission' 'vhost=/' 'user=foo'", + $command->toString(), + ); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $permissions = Permissions::of($server); $this->assertInstanceOf( @@ -66,14 +92,20 @@ public function testDelete() public function testReturnNothingWhenFailToDelete() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin 'delete' 'permission' 'vhost=/' 'user=foo'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $permissions = Permissions::of($server); $this->assertNull($permissions->delete('/', 'foo')->match( diff --git a/tests/Control/UsersTest.php b/tests/Control/UsersTest.php index 09e17db..6244cce 100644 --- a/tests/Control/UsersTest.php +++ b/tests/Control/UsersTest.php @@ -4,19 +4,32 @@ namespace Tests\Innmind\RabbitMQ\Management\Control; use Innmind\RabbitMQ\Management\Control\Users; -use Innmind\Server\Control\Servers\Mock; -use Innmind\Immutable\SideEffect; +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, +}; +use Innmind\Immutable\{ + Attempt, + SideEffect, +}; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class UsersTest extends TestCase { public function testDeclare() { - $server = Mock::new($this->assert()) - ->willExecute(fn($command) => $this->assertSame( - "rabbitmqadmin 'declare' 'user' 'name=foo' 'password=bar' 'tags=baz,foobar'", - $command->toString(), - )); + $server = Server::via( + function($command) { + $this->assertSame( + "rabbitmqadmin 'declare' 'user' 'name=foo' 'password=bar' 'tags=baz,foobar'", + $command->toString(), + ); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $users = Users::of($server); $this->assertInstanceOf( @@ -30,14 +43,20 @@ public function testDeclare() public function testReturnNothingWhenFailToDeclare() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin 'declare' 'user' 'name=foo' 'password=bar' 'tags=baz,foobar'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $users = Users::of($server); $this->assertNull($users->declare('foo', 'bar', 'baz', 'foobar')->match( @@ -48,11 +67,18 @@ public function testReturnNothingWhenFailToDeclare() public function testDelete() { - $server = Mock::new($this->assert()) - ->willExecute(fn($command) => $this->assertSame( - "rabbitmqadmin 'delete' 'user' 'name=foo'", - $command->toString(), - )); + $server = Server::via( + function($command) { + $this->assertSame( + "rabbitmqadmin 'delete' 'user' 'name=foo'", + $command->toString(), + ); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $users = Users::of($server); $this->assertInstanceOf( @@ -66,14 +92,20 @@ public function testDelete() public function testReturnNothingWhenFailToDelete() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin 'delete' 'user' 'name=foo'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $users = Users::of($server); $this->assertNull($users->delete('foo')->match( diff --git a/tests/Control/VHostsTest.php b/tests/Control/VHostsTest.php index 7f76f9b..379f8ed 100644 --- a/tests/Control/VHostsTest.php +++ b/tests/Control/VHostsTest.php @@ -4,19 +4,32 @@ namespace Tests\Innmind\RabbitMQ\Management\Control; use Innmind\RabbitMQ\Management\Control\VHosts; -use Innmind\Server\Control\Servers\Mock; -use Innmind\Immutable\SideEffect; +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, +}; +use Innmind\Immutable\{ + Attempt, + SideEffect, +}; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class VHostsTest extends TestCase { public function testDeclare() { - $server = Mock::new($this->assert()) - ->willExecute(fn($command) => $this->assertSame( - "rabbitmqadmin 'declare' 'vhost' 'name=foo'", - $command->toString(), - )); + $server = Server::via( + function($command) { + $this->assertSame( + "rabbitmqadmin 'declare' 'vhost' 'name=foo'", + $command->toString(), + ); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $vhosts = VHosts::of($server); $this->assertInstanceOf( @@ -30,14 +43,20 @@ public function testDeclare() public function testReturnNothingWhenFailToDeclare() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin 'declare' 'vhost' 'name=foo'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $vhosts = VHosts::of($server); $this->assertNull($vhosts->declare('foo')->match( @@ -48,11 +67,18 @@ public function testReturnNothingWhenFailToDeclare() public function testDelete() { - $server = Mock::new($this->assert()) - ->willExecute(fn($command) => $this->assertSame( - "rabbitmqadmin 'delete' 'vhost' 'name=foo'", - $command->toString(), - )); + $server = Server::via( + function($command) { + $this->assertSame( + "rabbitmqadmin 'delete' 'vhost' 'name=foo'", + $command->toString(), + ); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $vhosts = VHosts::of($server); $this->assertInstanceOf( @@ -66,14 +92,20 @@ public function testDelete() public function testReturnNothingWhenFailToDelete() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin 'delete' 'vhost' 'name=foo'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $vhosts = VHosts::of($server); $this->assertNull($vhosts->delete('foo')->match( diff --git a/tests/ControlTest.php b/tests/ControlTest.php index 33b5825..06ba434 100644 --- a/tests/ControlTest.php +++ b/tests/ControlTest.php @@ -9,14 +9,14 @@ Control\VHosts, Control\Permissions, }; -use Innmind\Server\Control\Servers\Mock; +use Innmind\Server\Control\Server; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class ControlTest extends TestCase { public function testInterface() { - $control = Control::of(Mock::new($this->assert())); + $control = Control::of(Server::via(static fn() => null)); $this->assertInstanceOf(Users::class, $control->users()); $this->assertInstanceOf(VHosts::class, $control->vhosts()); diff --git a/tests/Model/ChannelTest.php b/tests/Model/ChannelTest.php index a30b06f..f3cb451 100644 --- a/tests/Model/ChannelTest.php +++ b/tests/Model/ChannelTest.php @@ -13,7 +13,7 @@ State, Count }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Immutable\Maybe; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -36,7 +36,7 @@ public function testInterface() $consumers = Count::of(0), true, false, - $idle = Maybe::of(PointInTime::now()), + $idle = Maybe::of(Point::now()), ); $this->assertSame($name, $channel->name()); diff --git a/tests/Model/ConnectionTest.php b/tests/Model/ConnectionTest.php index 8eb2d43..6c2543b 100644 --- a/tests/Model/ConnectionTest.php +++ b/tests/Model/ConnectionTest.php @@ -16,7 +16,7 @@ Node\Name as NodeName, State }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Url\Authority\{ Host, Port @@ -29,7 +29,7 @@ public function testInterface() { $connection = Connection::of( $name = Name::of('foo'), - $connectedAt = PointInTime::now(), + $connectedAt = Point::now(), $timeout = Timeout::of(42), $vhost = VHostName::of('foo'), $user = UserName::of('foo'), diff --git a/tests/Model/Node/NameTest.php b/tests/Model/Node/NameTest.php index a2ee117..dae9353 100644 --- a/tests/Model/Node/NameTest.php +++ b/tests/Model/Node/NameTest.php @@ -26,6 +26,6 @@ public function testThrowWhenInvalidName() $this->expectException(DomainException::class); $this->expectExceptionMessage('whatever'); - Name::of('whatever'); + $_ = Name::of('whatever'); } } diff --git a/tests/Model/QueueTest.php b/tests/Model/QueueTest.php index 9eb8bd1..688f74a 100644 --- a/tests/Model/QueueTest.php +++ b/tests/Model/QueueTest.php @@ -12,7 +12,7 @@ Node\Name as NodeName, State }; -use Innmind\TimeContinuum\PointInTime; +use Innmind\Time\Point; use Innmind\Immutable\Maybe; use Innmind\BlackBox\PHPUnit\Framework\TestCase; @@ -27,7 +27,7 @@ public function testInterface() Count::of(0), Count::of(0), ), - $idleSince = Maybe::of(PointInTime::now()), + $idleSince = Maybe::of(Point::now()), $consumers = Count::of(0), $state = State::running, $node = NodeName::of('rabbit@foo'), diff --git a/tests/StatusTest.php b/tests/StatusTest.php index b5c2e0c..47ff557 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -7,30 +7,42 @@ Status, Status\Environment\Remote, }; -use Innmind\Server\Control\Servers\Mock; -use Innmind\TimeContinuum\{ +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, +}; +use Innmind\Time\{ Clock, Format, }; use Innmind\Url\Authority\Host; -use Innmind\Immutable\Sequence; +use Innmind\Immutable\{ + Sequence, + Attempt, +}; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class StatusTest extends TestCase { public function testUsers() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'users'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"name":"guest","password_hash":"ZbsaALrYfNHzlDnxzIZVSzP87B/sYM/lM+kZELz3qRk7vod+","hashing_algorithm":"rabbit_password_hashing_sha256","tags":"administrator"}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"name":"guest","password_hash":"ZbsaALrYfNHzlDnxzIZVSzP87B/sYM/lM+kZELz3qRk7vod+","hashing_algorithm":"rabbit_password_hashing_sha256","tags":"administrator"}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -39,7 +51,7 @@ public function testUsers() $users = $status->users(); $this->assertInstanceOf(Sequence::class, $users); - $this->assertCount(1, $users); + $this->assertSame(1, $users->size()); $user = $users->find(static fn() => true)->match( static fn($user) => $user, static fn() => null, @@ -53,23 +65,29 @@ public function testUsers() 'rabbit_password_hashing_sha256', $user->password()->algorithm(), ); - $this->assertCount(1, $user->tags()); + $this->assertSame(1, $user->tags()->size()); $this->assertSame(['administrator'], $user->tags()->toList()); } public function testRemoteUsers() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'users' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"name":"guest","password_hash":"ZbsaALrYfNHzlDnxzIZVSzP87B/sYM/lM+kZELz3qRk7vod+","hashing_algorithm":"rabbit_password_hashing_sha256","tags":"administrator"}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"name":"guest","password_hash":"ZbsaALrYfNHzlDnxzIZVSzP87B/sYM/lM+kZELz3qRk7vod+","hashing_algorithm":"rabbit_password_hashing_sha256","tags":"administrator"}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -79,7 +97,7 @@ public function testRemoteUsers() $users = $status->users(); $this->assertInstanceOf(Sequence::class, $users); - $this->assertCount(1, $users); + $this->assertSame(1, $users->size()); $user = $users->find(static fn() => true)->match( static fn($user) => $user, static fn() => null, @@ -93,41 +111,53 @@ public function testRemoteUsers() 'rabbit_password_hashing_sha256', $user->password()->algorithm(), ); - $this->assertCount(1, $user->tags()); + $this->assertSame(1, $user->tags()->size()); $this->assertSame(['administrator'], $user->tags()->toList()); } public function testThrowWhenFailToListUsers() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'users'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->users()); + $this->assertSame(0, $status->users()->size()); } public function testVhosts() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'vhosts'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"name":"/","tracing":false}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"name":"/","tracing":false}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -136,7 +166,7 @@ public function testVhosts() $vhosts = $status->vhosts(); $this->assertInstanceOf(Sequence::class, $vhosts); - $this->assertCount(1, $vhosts); + $this->assertSame(1, $vhosts->size()); $vhost = $vhosts->find(static fn() => true)->match( static fn($vhost) => $vhost, static fn() => null, @@ -150,17 +180,23 @@ public function testVhosts() public function testRemoteVhosts() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'vhosts' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"name":"/","tracing":false}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"name":"/","tracing":false}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -170,7 +206,7 @@ public function testRemoteVhosts() $vhosts = $status->vhosts(); $this->assertInstanceOf(Sequence::class, $vhosts); - $this->assertCount(1, $vhosts); + $this->assertSame(1, $vhosts->size()); $vhost = $vhosts->find(static fn() => true)->match( static fn($vhost) => $vhost, static fn() => null, @@ -184,35 +220,47 @@ public function testRemoteVhosts() public function testThrowWhenFailToListVhosts() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'vhosts'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->vhosts()); + $this->assertSame(0, $status->vhosts()->size()); } public function testConnections() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'connections'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"connected_at":1498810410111,"client_properties":{"product":"AMQPLib","platform":"PHP","version":"2.6","information":"","copyright":"","capabilities":{"authentication_failure_close":true,"publisher_confirms":true,"consumer_cancel_notify":true,"exchange_exchange_bindings":true,"basic.nack":true,"connection.blocked":true}},"channel_max":65535,"frame_max":131072,"timeout":60,"vhost":"/","user":"guest","protocol":"AMQP 0-9-1","ssl_hash":null,"ssl_cipher":null,"ssl_key_exchange":null,"ssl_protocol":null,"auth_mechanism":"AMQPLAIN","peer_cert_validity":null,"peer_cert_issuer":null,"peer_cert_subject":null,"ssl":false,"peer_host":"172.19.0.1","host":"172.19.0.2","peer_port":32788,"port":5672,"name":"172.19.0.1:32788 -> 172.19.0.2:5672","node":"rabbit@050becbb9cb3","type":"network","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":5},"reductions":3607,"channels":0,"state":"running","send_pend":0,"send_cnt":3,"recv_cnt":3,"recv_oct_details":{"rate":0.0},"recv_oct":357,"send_oct_details":{"rate":0.0},"send_oct":526,"reductions_details":{"rate":0.0},"reductions":3607}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"connected_at":1498810410111,"client_properties":{"product":"AMQPLib","platform":"PHP","version":"2.6","information":"","copyright":"","capabilities":{"authentication_failure_close":true,"publisher_confirms":true,"consumer_cancel_notify":true,"exchange_exchange_bindings":true,"basic.nack":true,"connection.blocked":true}},"channel_max":65535,"frame_max":131072,"timeout":60,"vhost":"/","user":"guest","protocol":"AMQP 0-9-1","ssl_hash":null,"ssl_cipher":null,"ssl_key_exchange":null,"ssl_protocol":null,"auth_mechanism":"AMQPLAIN","peer_cert_validity":null,"peer_cert_issuer":null,"peer_cert_subject":null,"ssl":false,"peer_host":"172.19.0.1","host":"172.19.0.2","peer_port":32788,"port":5672,"name":"172.19.0.1:32788 -> 172.19.0.2:5672","node":"rabbit@050becbb9cb3","type":"network","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":5},"reductions":3607,"channels":0,"state":"running","send_pend":0,"send_cnt":3,"recv_cnt":3,"recv_oct_details":{"rate":0.0},"recv_oct":357,"send_oct_details":{"rate":0.0},"send_oct":526,"reductions_details":{"rate":0.0},"reductions":3607}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -221,7 +269,7 @@ public function testConnections() $connections = $status->connections(); $this->assertInstanceOf(Sequence::class, $connections); - $this->assertCount(1, $connections); + $this->assertSame(1, $connections->size()); $connection = $connections->find(static fn() => true)->match( static fn($connection) => $connection, static fn() => null, @@ -248,17 +296,23 @@ public function testConnections() public function testRemoteConnections() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'connections' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"connected_at":1498810410111,"client_properties":{"product":"AMQPLib","platform":"PHP","version":"2.6","information":"","copyright":"","capabilities":{"authentication_failure_close":true,"publisher_confirms":true,"consumer_cancel_notify":true,"exchange_exchange_bindings":true,"basic.nack":true,"connection.blocked":true}},"channel_max":65535,"frame_max":131072,"timeout":60,"vhost":"/","user":"guest","protocol":"AMQP 0-9-1","ssl_hash":null,"ssl_cipher":null,"ssl_key_exchange":null,"ssl_protocol":null,"auth_mechanism":"AMQPLAIN","peer_cert_validity":null,"peer_cert_issuer":null,"peer_cert_subject":null,"ssl":false,"peer_host":"172.19.0.1","host":"172.19.0.2","peer_port":32788,"port":5672,"name":"172.19.0.1:32788 -> 172.19.0.2:5672","node":"rabbit@050becbb9cb3","type":"network","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":5},"reductions":3607,"channels":0,"state":"running","send_pend":0,"send_cnt":3,"recv_cnt":3,"recv_oct_details":{"rate":0.0},"recv_oct":357,"send_oct_details":{"rate":0.0},"send_oct":526,"reductions_details":{"rate":0.0},"reductions":3607}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"connected_at":1498810410111,"client_properties":{"product":"AMQPLib","platform":"PHP","version":"2.6","information":"","copyright":"","capabilities":{"authentication_failure_close":true,"publisher_confirms":true,"consumer_cancel_notify":true,"exchange_exchange_bindings":true,"basic.nack":true,"connection.blocked":true}},"channel_max":65535,"frame_max":131072,"timeout":60,"vhost":"/","user":"guest","protocol":"AMQP 0-9-1","ssl_hash":null,"ssl_cipher":null,"ssl_key_exchange":null,"ssl_protocol":null,"auth_mechanism":"AMQPLAIN","peer_cert_validity":null,"peer_cert_issuer":null,"peer_cert_subject":null,"ssl":false,"peer_host":"172.19.0.1","host":"172.19.0.2","peer_port":32788,"port":5672,"name":"172.19.0.1:32788 -> 172.19.0.2:5672","node":"rabbit@050becbb9cb3","type":"network","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":5},"reductions":3607,"channels":0,"state":"running","send_pend":0,"send_cnt":3,"recv_cnt":3,"recv_oct_details":{"rate":0.0},"recv_oct":357,"send_oct_details":{"rate":0.0},"send_oct":526,"reductions_details":{"rate":0.0},"reductions":3607}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -268,7 +322,7 @@ public function testRemoteConnections() $connections = $status->connections(); $this->assertInstanceOf(Sequence::class, $connections); - $this->assertCount(1, $connections); + $this->assertSame(1, $connections->size()); $connection = $connections->find(static fn() => true)->match( static fn($connection) => $connection, static fn() => null, @@ -295,35 +349,47 @@ public function testRemoteConnections() public function testReturnNothingWhenFailToListConnections() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'connections'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->connections()); + $this->assertSame(0, $status->connections()->size()); } public function testExchanges() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'exchanges'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"name":"","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.direct","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.fanout","vhost":"/","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.headers","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.match","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.rabbitmq.log","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.rabbitmq.trace","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.topic","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"crawl","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"name":"","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.direct","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.fanout","vhost":"/","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.headers","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.match","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.rabbitmq.log","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.rabbitmq.trace","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.topic","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"crawl","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -332,7 +398,7 @@ public function testExchanges() $exchanges = $status->exchanges(); $this->assertInstanceOf(Sequence::class, $exchanges); - $this->assertCount(9, $exchanges); + $this->assertSame(9, $exchanges->size()); $exchange = $exchanges->find(static fn() => true)->match( static fn($exchange) => $exchange, static fn() => null, @@ -347,17 +413,23 @@ public function testExchanges() public function testRemoteExchanges() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'exchanges' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"name":"","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.direct","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.fanout","vhost":"/","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.headers","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.match","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.rabbitmq.log","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.rabbitmq.trace","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.topic","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"crawl","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"name":"","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.direct","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.fanout","vhost":"/","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.headers","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.match","vhost":"/","type":"headers","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"amq.rabbitmq.log","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.rabbitmq.trace","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":true,"arguments":{}},{"name":"amq.topic","vhost":"/","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}},{"name":"crawl","vhost":"/","type":"direct","durable":true,"auto_delete":false,"internal":false,"arguments":{}}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -367,7 +439,7 @@ public function testRemoteExchanges() $exchanges = $status->exchanges(); $this->assertInstanceOf(Sequence::class, $exchanges); - $this->assertCount(9, $exchanges); + $this->assertSame(9, $exchanges->size()); $exchange = $exchanges->find(static fn() => true)->match( static fn($exchange) => $exchange, static fn() => null, @@ -382,35 +454,47 @@ public function testRemoteExchanges() public function testReturnNothingWhenFailToListExchanges() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'exchanges'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->exchanges()); + $this->assertSame(0, $status->exchanges()->size()); } public function testPermissions() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'permissions'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"user":"guest","vhost":"/","configure":".*","write":".*","read":".*"}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"user":"guest","vhost":"/","configure":".*","write":".*","read":".*"}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -419,7 +503,7 @@ public function testPermissions() $permissions = $status->permissions(); $this->assertInstanceOf(Sequence::class, $permissions); - $this->assertCount(1, $permissions); + $this->assertSame(1, $permissions->size()); $permission = $permissions->find(static fn() => true)->match( static fn($permission) => $permission, static fn() => null, @@ -433,17 +517,23 @@ public function testPermissions() public function testRemotePermissions() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'permissions' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"user":"guest","vhost":"/","configure":".*","write":".*","read":".*"}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"user":"guest","vhost":"/","configure":".*","write":".*","read":".*"}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -453,7 +543,7 @@ public function testRemotePermissions() $permissions = $status->permissions(); $this->assertInstanceOf(Sequence::class, $permissions); - $this->assertCount(1, $permissions); + $this->assertSame(1, $permissions->size()); $permission = $permissions->find(static fn() => true)->match( static fn($permission) => $permission, static fn() => null, @@ -467,35 +557,47 @@ public function testRemotePermissions() public function testReturnNothingWhenFailToListPermissions() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'permissions'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->permissions()); + $this->assertSame(0, $status->permissions()->size()); } public function testChannels() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'channels'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"vhost":"/","user":"guest","number":1,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":3},"reductions":2401,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":2,"messages_unconfirmed":3,"messages_unacknowledged":4,"consumer_count":1,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":2401,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}},{"vhost":"/","user":"guest","number":2,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (2)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":6},"reductions":905,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":0,"messages_unconfirmed":0,"messages_unacknowledged":0,"consumer_count":0,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":905,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"vhost":"/","user":"guest","number":1,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":3},"reductions":2401,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":2,"messages_unconfirmed":3,"messages_unacknowledged":4,"consumer_count":1,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":2401,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}},{"vhost":"/","user":"guest","number":2,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (2)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":6},"reductions":905,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":0,"messages_unconfirmed":0,"messages_unacknowledged":0,"consumer_count":0,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":905,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -504,7 +606,7 @@ public function testChannels() $channels = $status->channels(); $this->assertInstanceOf(Sequence::class, $channels); - $this->assertCount(2, $channels); + $this->assertSame(2, $channels->size()); $channel = $channels->find(static fn() => true)->match( static fn($channel) => $channel, static fn() => null, @@ -532,17 +634,23 @@ public function testChannels() public function testRemoteChannels() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'channels' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"vhost":"/","user":"guest","number":1,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":3},"reductions":2401,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":2,"messages_unconfirmed":3,"messages_unacknowledged":4,"consumer_count":1,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":2401,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}},{"vhost":"/","user":"guest","number":2,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (2)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":6},"reductions":905,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":0,"messages_unconfirmed":0,"messages_unacknowledged":0,"consumer_count":0,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":905,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"vhost":"/","user":"guest","number":1,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":3},"reductions":2401,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":2,"messages_unconfirmed":3,"messages_unacknowledged":4,"consumer_count":1,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":2401,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}},{"vhost":"/","user":"guest","number":2,"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (2)","node":"rabbit@050becbb9cb3","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":6},"reductions":905,"state":"running","global_prefetch_count":0,"prefetch_count":0,"acks_uncommitted":0,"messages_uncommitted":0,"messages_unconfirmed":0,"messages_unacknowledged":0,"consumer_count":0,"confirm":false,"transactional":false,"idle_since":"2017-06-30 8:13:31","reductions_details":{"rate":0.0},"reductions":905,"connection_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, $clock = Clock::live(), @@ -552,7 +660,7 @@ public function testRemoteChannels() $channels = $status->channels(); $this->assertInstanceOf(Sequence::class, $channels); - $this->assertCount(2, $channels); + $this->assertSame(2, $channels->size()); $channel = $channels->find(static fn() => true)->match( static fn($channel) => $channel, static fn() => null, @@ -580,35 +688,47 @@ public function testRemoteChannels() public function testReturnNothingWhenFailToListChannels() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'channels'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->channels()); + $this->assertSame(0, $status->channels()->size()); } public function testConsumers() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'consumers'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"arguments":{},"prefetch_count":0,"ack_required":true,"exclusive":false,"consumer_tag":"PHPPROCESS_Baptouuuu.local_7267","queue":{"name":"crawl","vhost":"/"},"channel_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","number":1,"user":"guest","connection_name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"arguments":{},"prefetch_count":0,"ack_required":true,"exclusive":false,"consumer_tag":"PHPPROCESS_Baptouuuu.local_7267","queue":{"name":"crawl","vhost":"/"},"channel_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","number":1,"user":"guest","connection_name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -617,7 +737,7 @@ public function testConsumers() $consumers = $status->consumers(); $this->assertInstanceOf(Sequence::class, $consumers); - $this->assertCount(1, $consumers); + $this->assertSame(1, $consumers->size()); $consumer = $consumers->find(static fn() => true)->match( static fn($consumer) => $consumer, static fn() => null, @@ -648,17 +768,23 @@ public function testConsumers() public function testRemoteConsumers() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'consumers' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"arguments":{},"prefetch_count":0,"ack_required":true,"exclusive":false,"consumer_tag":"PHPPROCESS_Baptouuuu.local_7267","queue":{"name":"crawl","vhost":"/"},"channel_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","number":1,"user":"guest","connection_name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"arguments":{},"prefetch_count":0,"ack_required":true,"exclusive":false,"consumer_tag":"PHPPROCESS_Baptouuuu.local_7267","queue":{"name":"crawl","vhost":"/"},"channel_details":{"name":"172.19.0.1:32788 -> 172.19.0.2:5672 (1)","number":1,"user":"guest","connection_name":"172.19.0.1:32788 -> 172.19.0.2:5672","peer_port":32788,"peer_host":"172.19.0.1"}}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -668,7 +794,7 @@ public function testRemoteConsumers() $consumers = $status->consumers(); $this->assertInstanceOf(Sequence::class, $consumers); - $this->assertCount(1, $consumers); + $this->assertSame(1, $consumers->size()); $consumer = $consumers->find(static fn() => true)->match( static fn($consumer) => $consumer, static fn() => null, @@ -699,35 +825,47 @@ public function testRemoteConsumers() public function testReturnNothingWhenFailToListConsumers() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'consumers'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->consumers()); + $this->assertSame(0, $status->consumers()->size()); } public function testQueues() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'queues'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"memory":14184,"reductions":8715,"reductions_details":{"rate":0.0},"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"idle_since":"2017-06-30 8:13:31","consumer_utilisation":null,"policy":null,"exclusive_consumer_tag":null,"consumers":1,"recoverable_slaves":null,"state":"running","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":1},"messages_ram":0,"messages_ready_ram":0,"messages_unacknowledged_ram":0,"messages_persistent":0,"message_bytes":0,"message_bytes_ready":0,"message_bytes_unacknowledged":0,"message_bytes_ram":0,"message_bytes_persistent":0,"head_message_timestamp":null,"disk_reads":0,"disk_writes":0,"backing_queue_status":{"mode":"default","q1":0,"q2":0,"delta":["delta","undefined",0,"undefined"],"q3":0,"q4":0,"len":0,"target_ram_count":"infinity","next_seq_id":0,"avg_ingress_rate":0.0,"avg_egress_rate":0.0,"avg_ack_ingress_rate":0.0,"avg_ack_egress_rate":0.0},"node":"rabbit@050becbb9cb3","arguments":{},"exclusive":false,"auto_delete":false,"durable":true,"vhost":"/","name":"crawl"}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"memory":14184,"reductions":8715,"reductions_details":{"rate":0.0},"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"idle_since":"2017-06-30 8:13:31","consumer_utilisation":null,"policy":null,"exclusive_consumer_tag":null,"consumers":1,"recoverable_slaves":null,"state":"running","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":1},"messages_ram":0,"messages_ready_ram":0,"messages_unacknowledged_ram":0,"messages_persistent":0,"message_bytes":0,"message_bytes_ready":0,"message_bytes_unacknowledged":0,"message_bytes_ram":0,"message_bytes_persistent":0,"head_message_timestamp":null,"disk_reads":0,"disk_writes":0,"backing_queue_status":{"mode":"default","q1":0,"q2":0,"delta":["delta","undefined",0,"undefined"],"q3":0,"q4":0,"len":0,"target_ram_count":"infinity","next_seq_id":0,"avg_ingress_rate":0.0,"avg_egress_rate":0.0,"avg_ack_ingress_rate":0.0,"avg_ack_egress_rate":0.0},"node":"rabbit@050becbb9cb3","arguments":{},"exclusive":false,"auto_delete":false,"durable":true,"vhost":"/","name":"crawl"}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -736,7 +874,7 @@ public function testQueues() $queues = $status->queues(); $this->assertInstanceOf(Sequence::class, $queues); - $this->assertCount(1, $queues); + $this->assertSame(1, $queues->size()); $queue = $queues->find(static fn() => true)->match( static fn($queue) => $queue, static fn() => null, @@ -778,17 +916,23 @@ public function testQueues() public function testRemoteQueues() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'queues' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"memory":14184,"reductions":8715,"reductions_details":{"rate":0.0},"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"idle_since":"2017-06-30 8:13:31","consumer_utilisation":null,"policy":null,"exclusive_consumer_tag":null,"consumers":1,"recoverable_slaves":null,"state":"running","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":1},"messages_ram":0,"messages_ready_ram":0,"messages_unacknowledged_ram":0,"messages_persistent":0,"message_bytes":0,"message_bytes_ready":0,"message_bytes_unacknowledged":0,"message_bytes_ram":0,"message_bytes_persistent":0,"head_message_timestamp":null,"disk_reads":0,"disk_writes":0,"backing_queue_status":{"mode":"default","q1":0,"q2":0,"delta":["delta","undefined",0,"undefined"],"q3":0,"q4":0,"len":0,"target_ram_count":"infinity","next_seq_id":0,"avg_ingress_rate":0.0,"avg_egress_rate":0.0,"avg_ack_ingress_rate":0.0,"avg_ack_egress_rate":0.0},"node":"rabbit@050becbb9cb3","arguments":{},"exclusive":false,"auto_delete":false,"durable":true,"vhost":"/","name":"crawl"}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"memory":14184,"reductions":8715,"reductions_details":{"rate":0.0},"messages":1,"messages_details":{"rate":0.0},"messages_ready":2,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":3,"messages_unacknowledged_details":{"rate":0.0},"idle_since":"2017-06-30 8:13:31","consumer_utilisation":null,"policy":null,"exclusive_consumer_tag":null,"consumers":1,"recoverable_slaves":null,"state":"running","garbage_collection":{"max_heap_size":0,"min_bin_vheap_size":46422,"min_heap_size":233,"fullsweep_after":65535,"minor_gcs":1},"messages_ram":0,"messages_ready_ram":0,"messages_unacknowledged_ram":0,"messages_persistent":0,"message_bytes":0,"message_bytes_ready":0,"message_bytes_unacknowledged":0,"message_bytes_ram":0,"message_bytes_persistent":0,"head_message_timestamp":null,"disk_reads":0,"disk_writes":0,"backing_queue_status":{"mode":"default","q1":0,"q2":0,"delta":["delta","undefined",0,"undefined"],"q3":0,"q4":0,"len":0,"target_ram_count":"infinity","next_seq_id":0,"avg_ingress_rate":0.0,"avg_egress_rate":0.0,"avg_ack_ingress_rate":0.0,"avg_ack_egress_rate":0.0},"node":"rabbit@050becbb9cb3","arguments":{},"exclusive":false,"auto_delete":false,"durable":true,"vhost":"/","name":"crawl"}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -798,7 +942,7 @@ public function testRemoteQueues() $queues = $status->queues(); $this->assertInstanceOf(Sequence::class, $queues); - $this->assertCount(1, $queues); + $this->assertSame(1, $queues->size()); $queue = $queues->find(static fn() => true)->match( static fn($queue) => $queue, static fn() => null, @@ -840,35 +984,47 @@ public function testRemoteQueues() public function testReturnNothingWhenFailToListQueues() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'queues'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->queues()); + $this->assertSame(0, $status->queues()->size()); } public function testNodes() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'nodes'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"cluster_links":[],"mem_used":65226200,"mem_used_details":{"rate":-1243.2},"fd_used":24,"fd_used_details":{"rate":0.0},"sockets_used":1,"sockets_used_details":{"rate":0.0},"proc_used":245,"proc_used_details":{"rate":0.0},"disk_free":56429953024,"disk_free_details":{"rate":0.0},"io_read_count":1,"io_read_count_details":{"rate":0.0},"io_read_bytes":1,"io_read_bytes_details":{"rate":0.0},"io_read_avg_time":0.677,"io_read_avg_time_details":{"rate":0.0},"io_write_count":0,"io_write_count_details":{"rate":0.0},"io_write_bytes":0,"io_write_bytes_details":{"rate":0.0},"io_write_avg_time":0.0,"io_write_avg_time_details":{"rate":0.0},"io_sync_count":0,"io_sync_count_details":{"rate":0.0},"io_sync_avg_time":0.0,"io_sync_avg_time_details":{"rate":0.0},"io_seek_count":0,"io_seek_count_details":{"rate":0.0},"io_seek_avg_time":0.0,"io_seek_avg_time_details":{"rate":0.0},"io_reopen_count":0,"io_reopen_count_details":{"rate":0.0},"mnesia_ram_tx_count":50,"mnesia_ram_tx_count_details":{"rate":0.0},"mnesia_disk_tx_count":1,"mnesia_disk_tx_count_details":{"rate":0.0},"msg_store_read_count":0,"msg_store_read_count_details":{"rate":0.0},"msg_store_write_count":0,"msg_store_write_count_details":{"rate":0.0},"queue_index_journal_write_count":0,"queue_index_journal_write_count_details":{"rate":0.0},"queue_index_write_count":0,"queue_index_write_count_details":{"rate":0.0},"queue_index_read_count":0,"queue_index_read_count_details":{"rate":0.0},"gc_num":108209,"gc_num_details":{"rate":10.2},"gc_bytes_reclaimed":1268145968,"gc_bytes_reclaimed_details":{"rate":148406.4},"context_switches":469344,"context_switches_details":{"rate":44.6},"io_file_handle_open_attempt_count":10,"io_file_handle_open_attempt_count_details":{"rate":0.0},"io_file_handle_open_attempt_avg_time":0.0837,"io_file_handle_open_attempt_avg_time_details":{"rate":0.0},"partitions":[],"os_pid":"117","fd_total":1048576,"sockets_total":943626,"mem_limit":838356172,"mem_alarm":false,"disk_free_limit":50000000,"disk_free_alarm":false,"proc_total":1048576,"rates_mode":"basic","uptime":7408973,"run_queue":0,"processors":4,"exchange_types":[{"name":"direct","description":"AMQP direct exchange, as per the AMQP specification","enabled":true},{"name":"fanout","description":"AMQP fanout exchange, as per the AMQP specification","enabled":true},{"name":"topic","description":"AMQP topic exchange, as per the AMQP specification","enabled":true},{"name":"headers","description":"AMQP headers exchange, as per the AMQP specification","enabled":true}],"auth_mechanisms":[{"name":"RABBIT-CR-DEMO","description":"RabbitMQ Demo challenge-response authentication mechanism","enabled":false},{"name":"AMQPLAIN","description":"QPid AMQPLAIN mechanism","enabled":true},{"name":"PLAIN","description":"SASL PLAIN authentication mechanism","enabled":true}],"applications":[{"name":"amqp_client","description":"RabbitMQ AMQP Client","version":"3.6.6"},{"name":"asn1","description":"The Erlang ASN1 compiler version 4.0.4","version":"4.0.4"},{"name":"compiler","description":"ERTS CXC 138 10","version":"7.0.3"},{"name":"crypto","description":"CRYPTO","version":"3.7.2"},{"name":"inets","description":"INETS CXC 138 49","version":"6.3.4"},{"name":"kernel","description":"ERTS CXC 138 10","version":"5.1.1"},{"name":"mnesia","description":"MNESIA CXC 138 12","version":"4.14.2"},{"name":"mochiweb","description":"MochiMedia Web Server","version":"2.13.1"},{"name":"os_mon","description":"CPO CXC 138 46","version":"2.4.1"},{"name":"public_key","description":"Public key infrastructure","version":"1.3"},{"name":"rabbit","description":"RabbitMQ","version":"3.6.6"},{"name":"rabbit_common","description":"","version":"3.6.6"},{"name":"rabbitmq_management","description":"RabbitMQ Management Console","version":"3.6.6"},{"name":"rabbitmq_management_agent","description":"RabbitMQ Management Agent","version":"3.6.6"},{"name":"rabbitmq_web_dispatch","description":"RabbitMQ Web Dispatcher","version":"3.6.6"},{"name":"ranch","description":"Socket acceptor pool for TCP protocols.","version":"1.2.1"},{"name":"sasl","description":"SASL CXC 138 11","version":"3.0.2"},{"name":"ssl","description":"Erlang/OTP SSL application","version":"8.1"},{"name":"stdlib","description":"ERTS CXC 138 10","version":"3.2"},{"name":"syntax_tools","description":"Syntax tools","version":"2.1.1"},{"name":"webmachine","description":"webmachine","version":"1.10.3"},{"name":"xmerl","description":"XML parser","version":"1.3.12"}],"contexts":[{"description":"RabbitMQ Management","path":"/","port":"15672"}],"log_file":"tty","sasl_log_file":"tty","db_dir":"/var/lib/rabbitmq/mnesia/rabbit@050becbb9cb3","config_files":["/etc/rabbitmq/rabbitmq.config"],"net_ticktime":60,"enabled_plugins":["rabbitmq_management"],"name":"rabbit@050becbb9cb3","type":"disc","running":true}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"cluster_links":[],"mem_used":65226200,"mem_used_details":{"rate":-1243.2},"fd_used":24,"fd_used_details":{"rate":0.0},"sockets_used":1,"sockets_used_details":{"rate":0.0},"proc_used":245,"proc_used_details":{"rate":0.0},"disk_free":56429953024,"disk_free_details":{"rate":0.0},"io_read_count":1,"io_read_count_details":{"rate":0.0},"io_read_bytes":1,"io_read_bytes_details":{"rate":0.0},"io_read_avg_time":0.677,"io_read_avg_time_details":{"rate":0.0},"io_write_count":0,"io_write_count_details":{"rate":0.0},"io_write_bytes":0,"io_write_bytes_details":{"rate":0.0},"io_write_avg_time":0.0,"io_write_avg_time_details":{"rate":0.0},"io_sync_count":0,"io_sync_count_details":{"rate":0.0},"io_sync_avg_time":0.0,"io_sync_avg_time_details":{"rate":0.0},"io_seek_count":0,"io_seek_count_details":{"rate":0.0},"io_seek_avg_time":0.0,"io_seek_avg_time_details":{"rate":0.0},"io_reopen_count":0,"io_reopen_count_details":{"rate":0.0},"mnesia_ram_tx_count":50,"mnesia_ram_tx_count_details":{"rate":0.0},"mnesia_disk_tx_count":1,"mnesia_disk_tx_count_details":{"rate":0.0},"msg_store_read_count":0,"msg_store_read_count_details":{"rate":0.0},"msg_store_write_count":0,"msg_store_write_count_details":{"rate":0.0},"queue_index_journal_write_count":0,"queue_index_journal_write_count_details":{"rate":0.0},"queue_index_write_count":0,"queue_index_write_count_details":{"rate":0.0},"queue_index_read_count":0,"queue_index_read_count_details":{"rate":0.0},"gc_num":108209,"gc_num_details":{"rate":10.2},"gc_bytes_reclaimed":1268145968,"gc_bytes_reclaimed_details":{"rate":148406.4},"context_switches":469344,"context_switches_details":{"rate":44.6},"io_file_handle_open_attempt_count":10,"io_file_handle_open_attempt_count_details":{"rate":0.0},"io_file_handle_open_attempt_avg_time":0.0837,"io_file_handle_open_attempt_avg_time_details":{"rate":0.0},"partitions":[],"os_pid":"117","fd_total":1048576,"sockets_total":943626,"mem_limit":838356172,"mem_alarm":false,"disk_free_limit":50000000,"disk_free_alarm":false,"proc_total":1048576,"rates_mode":"basic","uptime":7408973,"run_queue":0,"processors":4,"exchange_types":[{"name":"direct","description":"AMQP direct exchange, as per the AMQP specification","enabled":true},{"name":"fanout","description":"AMQP fanout exchange, as per the AMQP specification","enabled":true},{"name":"topic","description":"AMQP topic exchange, as per the AMQP specification","enabled":true},{"name":"headers","description":"AMQP headers exchange, as per the AMQP specification","enabled":true}],"auth_mechanisms":[{"name":"RABBIT-CR-DEMO","description":"RabbitMQ Demo challenge-response authentication mechanism","enabled":false},{"name":"AMQPLAIN","description":"QPid AMQPLAIN mechanism","enabled":true},{"name":"PLAIN","description":"SASL PLAIN authentication mechanism","enabled":true}],"applications":[{"name":"amqp_client","description":"RabbitMQ AMQP Client","version":"3.6.6"},{"name":"asn1","description":"The Erlang ASN1 compiler version 4.0.4","version":"4.0.4"},{"name":"compiler","description":"ERTS CXC 138 10","version":"7.0.3"},{"name":"crypto","description":"CRYPTO","version":"3.7.2"},{"name":"inets","description":"INETS CXC 138 49","version":"6.3.4"},{"name":"kernel","description":"ERTS CXC 138 10","version":"5.1.1"},{"name":"mnesia","description":"MNESIA CXC 138 12","version":"4.14.2"},{"name":"mochiweb","description":"MochiMedia Web Server","version":"2.13.1"},{"name":"os_mon","description":"CPO CXC 138 46","version":"2.4.1"},{"name":"public_key","description":"Public key infrastructure","version":"1.3"},{"name":"rabbit","description":"RabbitMQ","version":"3.6.6"},{"name":"rabbit_common","description":"","version":"3.6.6"},{"name":"rabbitmq_management","description":"RabbitMQ Management Console","version":"3.6.6"},{"name":"rabbitmq_management_agent","description":"RabbitMQ Management Agent","version":"3.6.6"},{"name":"rabbitmq_web_dispatch","description":"RabbitMQ Web Dispatcher","version":"3.6.6"},{"name":"ranch","description":"Socket acceptor pool for TCP protocols.","version":"1.2.1"},{"name":"sasl","description":"SASL CXC 138 11","version":"3.0.2"},{"name":"ssl","description":"Erlang/OTP SSL application","version":"8.1"},{"name":"stdlib","description":"ERTS CXC 138 10","version":"3.2"},{"name":"syntax_tools","description":"Syntax tools","version":"2.1.1"},{"name":"webmachine","description":"webmachine","version":"1.10.3"},{"name":"xmerl","description":"XML parser","version":"1.3.12"}],"contexts":[{"description":"RabbitMQ Management","path":"/","port":"15672"}],"log_file":"tty","sasl_log_file":"tty","db_dir":"/var/lib/rabbitmq/mnesia/rabbit@050becbb9cb3","config_files":["/etc/rabbitmq/rabbitmq.config"],"net_ticktime":60,"enabled_plugins":["rabbitmq_management"],"name":"rabbit@050becbb9cb3","type":"disc","running":true}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -877,7 +1033,7 @@ public function testNodes() $nodes = $status->nodes(); $this->assertInstanceOf(Sequence::class, $nodes); - $this->assertCount(1, $nodes); + $this->assertSame(1, $nodes->size()); $node = $nodes->find(static fn() => true)->match( static fn($node) => $node, static fn() => null, @@ -895,17 +1051,23 @@ public function testNodes() public function testRemoteNodes() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'nodes' '--host=rabbit.innmind.com' '--port=15672' '--username=guest' '--password=guest'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([[ - '[{"cluster_links":[],"mem_used":65226200,"mem_used_details":{"rate":-1243.2},"fd_used":24,"fd_used_details":{"rate":0.0},"sockets_used":1,"sockets_used_details":{"rate":0.0},"proc_used":245,"proc_used_details":{"rate":0.0},"disk_free":56429953024,"disk_free_details":{"rate":0.0},"io_read_count":1,"io_read_count_details":{"rate":0.0},"io_read_bytes":1,"io_read_bytes_details":{"rate":0.0},"io_read_avg_time":0.677,"io_read_avg_time_details":{"rate":0.0},"io_write_count":0,"io_write_count_details":{"rate":0.0},"io_write_bytes":0,"io_write_bytes_details":{"rate":0.0},"io_write_avg_time":0.0,"io_write_avg_time_details":{"rate":0.0},"io_sync_count":0,"io_sync_count_details":{"rate":0.0},"io_sync_avg_time":0.0,"io_sync_avg_time_details":{"rate":0.0},"io_seek_count":0,"io_seek_count_details":{"rate":0.0},"io_seek_avg_time":0.0,"io_seek_avg_time_details":{"rate":0.0},"io_reopen_count":0,"io_reopen_count_details":{"rate":0.0},"mnesia_ram_tx_count":50,"mnesia_ram_tx_count_details":{"rate":0.0},"mnesia_disk_tx_count":1,"mnesia_disk_tx_count_details":{"rate":0.0},"msg_store_read_count":0,"msg_store_read_count_details":{"rate":0.0},"msg_store_write_count":0,"msg_store_write_count_details":{"rate":0.0},"queue_index_journal_write_count":0,"queue_index_journal_write_count_details":{"rate":0.0},"queue_index_write_count":0,"queue_index_write_count_details":{"rate":0.0},"queue_index_read_count":0,"queue_index_read_count_details":{"rate":0.0},"gc_num":108209,"gc_num_details":{"rate":10.2},"gc_bytes_reclaimed":1268145968,"gc_bytes_reclaimed_details":{"rate":148406.4},"context_switches":469344,"context_switches_details":{"rate":44.6},"io_file_handle_open_attempt_count":10,"io_file_handle_open_attempt_count_details":{"rate":0.0},"io_file_handle_open_attempt_avg_time":0.0837,"io_file_handle_open_attempt_avg_time_details":{"rate":0.0},"partitions":[],"os_pid":"117","fd_total":1048576,"sockets_total":943626,"mem_limit":838356172,"mem_alarm":false,"disk_free_limit":50000000,"disk_free_alarm":false,"proc_total":1048576,"rates_mode":"basic","uptime":7408973,"run_queue":0,"processors":4,"exchange_types":[{"name":"direct","description":"AMQP direct exchange, as per the AMQP specification","enabled":true},{"name":"fanout","description":"AMQP fanout exchange, as per the AMQP specification","enabled":true},{"name":"topic","description":"AMQP topic exchange, as per the AMQP specification","enabled":true},{"name":"headers","description":"AMQP headers exchange, as per the AMQP specification","enabled":true}],"auth_mechanisms":[{"name":"RABBIT-CR-DEMO","description":"RabbitMQ Demo challenge-response authentication mechanism","enabled":false},{"name":"AMQPLAIN","description":"QPid AMQPLAIN mechanism","enabled":true},{"name":"PLAIN","description":"SASL PLAIN authentication mechanism","enabled":true}],"applications":[{"name":"amqp_client","description":"RabbitMQ AMQP Client","version":"3.6.6"},{"name":"asn1","description":"The Erlang ASN1 compiler version 4.0.4","version":"4.0.4"},{"name":"compiler","description":"ERTS CXC 138 10","version":"7.0.3"},{"name":"crypto","description":"CRYPTO","version":"3.7.2"},{"name":"inets","description":"INETS CXC 138 49","version":"6.3.4"},{"name":"kernel","description":"ERTS CXC 138 10","version":"5.1.1"},{"name":"mnesia","description":"MNESIA CXC 138 12","version":"4.14.2"},{"name":"mochiweb","description":"MochiMedia Web Server","version":"2.13.1"},{"name":"os_mon","description":"CPO CXC 138 46","version":"2.4.1"},{"name":"public_key","description":"Public key infrastructure","version":"1.3"},{"name":"rabbit","description":"RabbitMQ","version":"3.6.6"},{"name":"rabbit_common","description":"","version":"3.6.6"},{"name":"rabbitmq_management","description":"RabbitMQ Management Console","version":"3.6.6"},{"name":"rabbitmq_management_agent","description":"RabbitMQ Management Agent","version":"3.6.6"},{"name":"rabbitmq_web_dispatch","description":"RabbitMQ Web Dispatcher","version":"3.6.6"},{"name":"ranch","description":"Socket acceptor pool for TCP protocols.","version":"1.2.1"},{"name":"sasl","description":"SASL CXC 138 11","version":"3.0.2"},{"name":"ssl","description":"Erlang/OTP SSL application","version":"8.1"},{"name":"stdlib","description":"ERTS CXC 138 10","version":"3.2"},{"name":"syntax_tools","description":"Syntax tools","version":"2.1.1"},{"name":"webmachine","description":"webmachine","version":"1.10.3"},{"name":"xmerl","description":"XML parser","version":"1.3.12"}],"contexts":[{"description":"RabbitMQ Management","path":"/","port":"15672"}],"log_file":"tty","sasl_log_file":"tty","db_dir":"/var/lib/rabbitmq/mnesia/rabbit@050becbb9cb3","config_files":["/etc/rabbitmq/rabbitmq.config"],"net_ticktime":60,"enabled_plugins":["rabbitmq_management"],"name":"rabbit@050becbb9cb3","type":"disc","running":true}]', - 'output', - ]]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([[ + '[{"cluster_links":[],"mem_used":65226200,"mem_used_details":{"rate":-1243.2},"fd_used":24,"fd_used_details":{"rate":0.0},"sockets_used":1,"sockets_used_details":{"rate":0.0},"proc_used":245,"proc_used_details":{"rate":0.0},"disk_free":56429953024,"disk_free_details":{"rate":0.0},"io_read_count":1,"io_read_count_details":{"rate":0.0},"io_read_bytes":1,"io_read_bytes_details":{"rate":0.0},"io_read_avg_time":0.677,"io_read_avg_time_details":{"rate":0.0},"io_write_count":0,"io_write_count_details":{"rate":0.0},"io_write_bytes":0,"io_write_bytes_details":{"rate":0.0},"io_write_avg_time":0.0,"io_write_avg_time_details":{"rate":0.0},"io_sync_count":0,"io_sync_count_details":{"rate":0.0},"io_sync_avg_time":0.0,"io_sync_avg_time_details":{"rate":0.0},"io_seek_count":0,"io_seek_count_details":{"rate":0.0},"io_seek_avg_time":0.0,"io_seek_avg_time_details":{"rate":0.0},"io_reopen_count":0,"io_reopen_count_details":{"rate":0.0},"mnesia_ram_tx_count":50,"mnesia_ram_tx_count_details":{"rate":0.0},"mnesia_disk_tx_count":1,"mnesia_disk_tx_count_details":{"rate":0.0},"msg_store_read_count":0,"msg_store_read_count_details":{"rate":0.0},"msg_store_write_count":0,"msg_store_write_count_details":{"rate":0.0},"queue_index_journal_write_count":0,"queue_index_journal_write_count_details":{"rate":0.0},"queue_index_write_count":0,"queue_index_write_count_details":{"rate":0.0},"queue_index_read_count":0,"queue_index_read_count_details":{"rate":0.0},"gc_num":108209,"gc_num_details":{"rate":10.2},"gc_bytes_reclaimed":1268145968,"gc_bytes_reclaimed_details":{"rate":148406.4},"context_switches":469344,"context_switches_details":{"rate":44.6},"io_file_handle_open_attempt_count":10,"io_file_handle_open_attempt_count_details":{"rate":0.0},"io_file_handle_open_attempt_avg_time":0.0837,"io_file_handle_open_attempt_avg_time_details":{"rate":0.0},"partitions":[],"os_pid":"117","fd_total":1048576,"sockets_total":943626,"mem_limit":838356172,"mem_alarm":false,"disk_free_limit":50000000,"disk_free_alarm":false,"proc_total":1048576,"rates_mode":"basic","uptime":7408973,"run_queue":0,"processors":4,"exchange_types":[{"name":"direct","description":"AMQP direct exchange, as per the AMQP specification","enabled":true},{"name":"fanout","description":"AMQP fanout exchange, as per the AMQP specification","enabled":true},{"name":"topic","description":"AMQP topic exchange, as per the AMQP specification","enabled":true},{"name":"headers","description":"AMQP headers exchange, as per the AMQP specification","enabled":true}],"auth_mechanisms":[{"name":"RABBIT-CR-DEMO","description":"RabbitMQ Demo challenge-response authentication mechanism","enabled":false},{"name":"AMQPLAIN","description":"QPid AMQPLAIN mechanism","enabled":true},{"name":"PLAIN","description":"SASL PLAIN authentication mechanism","enabled":true}],"applications":[{"name":"amqp_client","description":"RabbitMQ AMQP Client","version":"3.6.6"},{"name":"asn1","description":"The Erlang ASN1 compiler version 4.0.4","version":"4.0.4"},{"name":"compiler","description":"ERTS CXC 138 10","version":"7.0.3"},{"name":"crypto","description":"CRYPTO","version":"3.7.2"},{"name":"inets","description":"INETS CXC 138 49","version":"6.3.4"},{"name":"kernel","description":"ERTS CXC 138 10","version":"5.1.1"},{"name":"mnesia","description":"MNESIA CXC 138 12","version":"4.14.2"},{"name":"mochiweb","description":"MochiMedia Web Server","version":"2.13.1"},{"name":"os_mon","description":"CPO CXC 138 46","version":"2.4.1"},{"name":"public_key","description":"Public key infrastructure","version":"1.3"},{"name":"rabbit","description":"RabbitMQ","version":"3.6.6"},{"name":"rabbit_common","description":"","version":"3.6.6"},{"name":"rabbitmq_management","description":"RabbitMQ Management Console","version":"3.6.6"},{"name":"rabbitmq_management_agent","description":"RabbitMQ Management Agent","version":"3.6.6"},{"name":"rabbitmq_web_dispatch","description":"RabbitMQ Web Dispatcher","version":"3.6.6"},{"name":"ranch","description":"Socket acceptor pool for TCP protocols.","version":"1.2.1"},{"name":"sasl","description":"SASL CXC 138 11","version":"3.0.2"},{"name":"ssl","description":"Erlang/OTP SSL application","version":"8.1"},{"name":"stdlib","description":"ERTS CXC 138 10","version":"3.2"},{"name":"syntax_tools","description":"Syntax tools","version":"2.1.1"},{"name":"webmachine","description":"webmachine","version":"1.10.3"},{"name":"xmerl","description":"XML parser","version":"1.3.12"}],"contexts":[{"description":"RabbitMQ Management","path":"/","port":"15672"}],"log_file":"tty","sasl_log_file":"tty","db_dir":"/var/lib/rabbitmq/mnesia/rabbit@050becbb9cb3","config_files":["/etc/rabbitmq/rabbitmq.config"],"net_ticktime":60,"enabled_plugins":["rabbitmq_management"],"name":"rabbit@050becbb9cb3","type":"disc","running":true}]', + 'output', + ]]) + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), @@ -915,7 +1077,7 @@ public function testRemoteNodes() $nodes = $status->nodes(); $this->assertInstanceOf(Sequence::class, $nodes); - $this->assertCount(1, $nodes); + $this->assertSame(1, $nodes->size()); $node = $nodes->find(static fn() => true)->match( static fn($node) => $node, static fn() => null, @@ -933,19 +1095,25 @@ public function testRemoteNodes() public function testReturnNothingWhenFailToListNodes() { - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "rabbitmqadmin '-f' 'raw_json' 'list' 'nodes'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $status = Status::of( $server, Clock::live(), ); - $this->assertCount(0, $status->nodes()); + $this->assertSame(0, $status->nodes()->size()); } }