From 291915a413c8dbf6b6bbce77b01568835a6ca8aa Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Sat, 7 Dec 2024 21:30:50 -0500 Subject: [PATCH] fix test --- .../Reverb/Publishing/RedisPubSubProvider.php | 18 +++++++++--------- .../Publishing/RedisPubSubProviderTest.php | 13 ++++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Servers/Reverb/Publishing/RedisPubSubProvider.php b/src/Servers/Reverb/Publishing/RedisPubSubProvider.php index e1ff94d..26642b3 100644 --- a/src/Servers/Reverb/Publishing/RedisPubSubProvider.php +++ b/src/Servers/Reverb/Publishing/RedisPubSubProvider.php @@ -27,24 +27,24 @@ public function __construct( */ public function connect(LoopInterface $loop): void { - $this->subscribingClient = new RedisClient( + $this->publishingClient = new RedisClient( $loop, $this->clientFactory, $this->channel, - 'subscriber', - $this->server, - fn () => $this->subscribe() + 'publisher', + $this->server ); - $this->subscribingClient->connect(); + $this->publishingClient->connect(); - $this->publishingClient = new RedisClient( + $this->subscribingClient = new RedisClient( $loop, $this->clientFactory, $this->channel, - 'publisher', - $this->server + 'subscriber', + $this->server, + fn () => $this->subscribe() ); - $this->publishingClient->connect(); + $this->subscribingClient->connect(); } /** diff --git a/tests/Unit/Servers/Reverb/Publishing/RedisPubSubProviderTest.php b/tests/Unit/Servers/Reverb/Publishing/RedisPubSubProviderTest.php index 7cce7b1..bc2a769 100644 --- a/tests/Unit/Servers/Reverb/Publishing/RedisPubSubProviderTest.php +++ b/tests/Unit/Servers/Reverb/Publishing/RedisPubSubProviderTest.php @@ -5,6 +5,7 @@ use Laravel\Reverb\Servers\Reverb\Publishing\RedisClientFactory; use Laravel\Reverb\Servers\Reverb\Publishing\RedisPubSubProvider; use React\EventLoop\LoopInterface; +use React\Promise\Promise; it('resubscribes to the scaling channel on unsubscribe event', function () { $channel = 'reverb'; @@ -21,6 +22,10 @@ ->with('message', Mockery::any()) ->zeroOrMoreTimes(); + $subscribingClient->shouldReceive('on') + ->with('close', Mockery::any()) + ->zeroOrMoreTimes(); + $subscribingClient->shouldReceive('subscribe') ->twice() ->with($channel); @@ -30,17 +35,15 @@ // The first call to make() will return a publishing client $clientFactory->shouldReceive('make') ->once() - ->andReturn(Mockery::mock(Client::class)); + ->andReturn(new Promise(fn (callable $resolve) => $resolve)); $clientFactory->shouldReceive('make') ->once() - ->andReturn($subscribingClient); + ->andReturn(new Promise(fn (callable $resolve) => $resolve($subscribingClient))); $provider = new RedisPubSubProvider($clientFactory, Mockery::mock(PubSubIncomingMessageHandler::class), $channel); $provider->connect(Mockery::mock(LoopInterface::class)); - - $provider->subscribe(); -})->skip(); +}); it('can successfully reconnect', function () {})->todo();