From ed41ad5ca0cbdef3ff2b038d3a0cd219c1d4184f Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Fri, 18 Sep 2020 12:53:36 +0300 Subject: [PATCH] Moved tests across classes --- src/ChannelManagers/RedisChannelManager.php | 30 +- tests/PresenceChannelTest.php | 143 ++++++++ tests/PrivateChannelTest.php | 110 +++++++ tests/PublicChannelTest.php | 110 +++++++ tests/ReplicationTest.php | 343 +------------------- 5 files changed, 380 insertions(+), 356 deletions(-) diff --git a/src/ChannelManagers/RedisChannelManager.php b/src/ChannelManagers/RedisChannelManager.php index fe92b95..28bd1ef 100644 --- a/src/ChannelManagers/RedisChannelManager.php +++ b/src/ChannelManagers/RedisChannelManager.php @@ -598,17 +598,15 @@ class RedisChannelManager extends LocalChannelManager $stop = "({$stop}"; } - return $this->publishClient->zrangebyscore( - $this->getRedisKey(null, null, ['sockets']), - $start, $stop - ) - ->then(function ($list) { - return collect($list)->mapWithKeys(function ($appWithSocket) { - [$appId, $socketId] = explode(':', $appWithSocket); + return $this->publishClient + ->zrangebyscore($this->getRedisKey(null, null, ['sockets']), $start, $stop) + ->then(function ($list) { + return collect($list)->mapWithKeys(function ($appWithSocket) { + [$appId, $socketId] = explode(':', $appWithSocket); - return [$socketId => $appId]; - })->toArray(); - }); + return [$socketId => $appId]; + })->toArray(); + }); } /** @@ -621,8 +619,7 @@ class RedisChannelManager extends LocalChannelManager public function addChannelToSet($appId, string $channel) { return $this->publishClient->sadd( - $this->getRedisKey($appId, null, ['channels']), - $channel + $this->getRedisKey($appId, null, ['channels']), $channel ); } @@ -636,8 +633,7 @@ class RedisChannelManager extends LocalChannelManager public function removeChannelFromSet($appId, string $channel) { return $this->publishClient->srem( - $this->getRedisKey($appId, null, ['channels']), - $channel + $this->getRedisKey($appId, null, ['channels']), $channel ); } @@ -712,8 +708,7 @@ class RedisChannelManager extends LocalChannelManager protected function addUserSocket($appId, string $channel, stdClass $user, string $socketId) { $this->publishClient->sadd( - $this->getRedisKey($appId, $channel, [$user->user_id, 'userSockets']), - $socketId + $this->getRedisKey($appId, $channel, [$user->user_id, 'userSockets']), $socketId ); } @@ -729,8 +724,7 @@ class RedisChannelManager extends LocalChannelManager protected function removeUserSocket($appId, string $channel, stdClass $user, string $socketId) { $this->publishClient->srem( - $this->getRedisKey($appId, $channel, [$user->user_id, 'userSockets']), - $socketId + $this->getRedisKey($appId, $channel, [$user->user_id, 'userSockets']), $socketId ); } diff --git a/tests/PresenceChannelTest.php b/tests/PresenceChannelTest.php index 2317fca..6927b14 100644 --- a/tests/PresenceChannelTest.php +++ b/tests/PresenceChannelTest.php @@ -3,6 +3,7 @@ namespace BeyondCode\LaravelWebSockets\Test; use BeyondCode\LaravelWebSockets\Server\Exceptions\InvalidSignature; +use Carbon\Carbon; use Ratchet\ConnectionInterface; class PresenceChannelTest extends TestCase @@ -312,4 +313,146 @@ class PresenceChannelTest extends TestCase $this->assertCount(1, $sockets); }); } + + public function test_not_ponged_connections_do_get_removed_for_presence_channels() + { + $this->runOnlyOnRedisReplication(); + + $activeConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 1]); + $obsoleteConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 2]); + + // The active connection just pinged, it should not be closed. + $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); + + // Make the connection look like it was lost 1 day ago. + $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'presence-channel') + ->then(function ($count) { + $this->assertEquals(2, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(1, $expiredConnections); + }); + + $this->channelManager + ->getChannelMembers('1234', 'presence-channel') + ->then(function ($members) { + $this->assertCount(2, $members); + }); + + $this->channelManager->removeObsoleteConnections(); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'presence-channel') + ->then(function ($count) { + $this->assertEquals(1, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(0, $expiredConnections); + }); + + $this->channelManager + ->getChannelMembers('1234', 'presence-channel') + ->then(function ($members) { + $this->assertCount(1, $members); + }); + } + + public function test_events_are_processed_by_on_message_on_presence_channels() + { + $this->runOnlyOnRedisReplication(); + + $user = [ + 'user_id' => 1, + 'user_info' => [ + 'name' => 'Rick', + ], + ]; + + $connection = $this->newPresenceConnection('presence-channel', $user); + + $encodedUser = json_encode($user); + + $message = new Mocks\SignedMessage([ + 'appId' => '1234', + 'serverId' => 'different_server_id', + 'event' => 'some-event', + 'data' => [ + 'channel' => 'presence-channel', + 'channel_data' => $encodedUser, + 'test' => 'yes', + ], + ], $connection, 'presence-channel', $encodedUser); + + $this->channelManager->onMessage( + $this->channelManager->getRedisKey('1234', 'presence-channel'), + $message->getPayload() + ); + + // The message does not contain appId and serverId anymore. + $message = new Mocks\SignedMessage([ + 'event' => 'some-event', + 'data' => [ + 'channel' => 'presence-channel', + 'channel_data' => $encodedUser, + 'test' => 'yes', + ], + ], $connection, 'presence-channel', $encodedUser); + + $connection->assertSentEvent('some-event', $message->getPayloadAsArray()); + } + + public function test_events_get_replicated_across_connections_for_presence_channels() + { + $this->runOnlyOnRedisReplication(); + + $connection = $this->newPresenceConnection('presence-channel'); + $receiver = $this->newPresenceConnection('presence-channel', ['user_id' => 2]); + + $user = [ + 'user_id' => 1, + 'user_info' => [ + 'name' => 'Rick', + ], + ]; + + $encodedUser = json_encode($user); + + $message = new Mocks\SignedMessage([ + 'appId' => '1234', + 'serverId' => $this->channelManager->getServerId(), + 'event' => 'some-event', + 'data' => [ + 'channel' => 'presence-channel', + 'channel_data' => $encodedUser, + 'test' => 'yes', + ], + 'socketId' => $connection->socketId, + ], $connection, 'presence-channel', $encodedUser); + + $channel = $this->channelManager->find('1234', 'presence-channel'); + + $channel->broadcastToEveryoneExcept( + $message->getPayloadAsObject(), $connection->socketId, '1234', true + ); + + $receiver->assertSentEvent('some-event', $message->getPayloadAsArray()); + + $this->getSubscribeClient() + ->assertNothingDispatched(); + + $this->getPublishClient() + ->assertCalledWithArgs('publish', [ + $this->channelManager->getRedisKey('1234', 'presence-channel'), + $message->getPayload(), + ]); + } } diff --git a/tests/PrivateChannelTest.php b/tests/PrivateChannelTest.php index 53f325b..d37517c 100644 --- a/tests/PrivateChannelTest.php +++ b/tests/PrivateChannelTest.php @@ -3,6 +3,7 @@ namespace BeyondCode\LaravelWebSockets\Test; use BeyondCode\LaravelWebSockets\Server\Exceptions\InvalidSignature; +use Carbon\Carbon; use Ratchet\ConnectionInterface; class PrivateChannelTest extends TestCase @@ -153,4 +154,113 @@ class PrivateChannelTest extends TestCase } }); } + + public function test_not_ponged_connections_do_get_removed_for_private_channels() + { + $this->runOnlyOnRedisReplication(); + + $activeConnection = $this->newPrivateConnection('private-channel'); + $obsoleteConnection = $this->newPrivateConnection('private-channel'); + + // The active connection just pinged, it should not be closed. + $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); + + // Make the connection look like it was lost 1 day ago. + $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'private-channel') + ->then(function ($count) { + $this->assertEquals(2, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(1, $expiredConnections); + }); + + $this->channelManager->removeObsoleteConnections(); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'private-channel') + ->then(function ($count) { + $this->assertEquals(1, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(0, $expiredConnections); + }); + } + + public function test_events_are_processed_by_on_message_on_private_channels() + { + $this->runOnlyOnRedisReplication(); + + $connection = $this->newPrivateConnection('private-channel'); + + $message = new Mocks\SignedMessage([ + 'appId' => '1234', + 'serverId' => 'different_server_id', + 'event' => 'some-event', + 'data' => [ + 'channel' => 'private-channel', + 'test' => 'yes', + ], + ], $connection, 'private-channel'); + + $this->channelManager->onMessage( + $this->channelManager->getRedisKey('1234', 'private-channel'), + $message->getPayload() + ); + + // The message does not contain appId and serverId anymore. + $message = new Mocks\SignedMessage([ + 'event' => 'some-event', + 'data' => [ + 'channel' => 'private-channel', + 'test' => 'yes', + ], + ], $connection, 'private-channel'); + + $connection->assertSentEvent('some-event', $message->getPayloadAsArray()); + } + + public function test_events_get_replicated_across_connections_for_private_channels() + { + $this->runOnlyOnRedisReplication(); + + $connection = $this->newPrivateConnection('private-channel'); + $receiver = $this->newPrivateConnection('private-channel'); + + $message = new Mocks\SignedMessage([ + 'appId' => '1234', + 'serverId' => $this->channelManager->getServerId(), + 'event' => 'some-event', + 'data' => [ + 'channel' => 'private-channel', + 'test' => 'yes', + ], + 'socketId' => $connection->socketId, + ], $connection, 'private-channel'); + + $channel = $this->channelManager->find('1234', 'private-channel'); + + $channel->broadcastToEveryoneExcept( + $message->getPayloadAsObject(), $connection->socketId, '1234', true + ); + + $receiver->assertSentEvent('some-event', $message->getPayloadAsArray()); + + $this->getSubscribeClient() + ->assertNothingDispatched(); + + $this->getPublishClient() + ->assertCalledWithArgs('publish', [ + $this->channelManager->getRedisKey('1234', 'private-channel'), + $message->getPayload(), + ]); + } } diff --git a/tests/PublicChannelTest.php b/tests/PublicChannelTest.php index 95d2f50..4c755fb 100644 --- a/tests/PublicChannelTest.php +++ b/tests/PublicChannelTest.php @@ -2,6 +2,7 @@ namespace BeyondCode\LaravelWebSockets\Test; +use Carbon\Carbon; use Ratchet\ConnectionInterface; class PublicChannelTest extends TestCase @@ -134,4 +135,113 @@ class PublicChannelTest extends TestCase } }); } + + public function test_not_ponged_connections_do_get_removed_for_public_channels() + { + $this->runOnlyOnRedisReplication(); + + $activeConnection = $this->newActiveConnection(['public-channel']); + $obsoleteConnection = $this->newActiveConnection(['public-channel']); + + // The active connection just pinged, it should not be closed. + $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); + + // Make the connection look like it was lost 1 day ago. + $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'public-channel') + ->then(function ($count) { + $this->assertEquals(2, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(1, $expiredConnections); + }); + + $this->channelManager->removeObsoleteConnections(); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'public-channel') + ->then(function ($count) { + $this->assertEquals(1, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(0, $expiredConnections); + }); + } + + public function test_events_are_processed_by_on_message_on_public_channels() + { + $this->runOnlyOnRedisReplication(); + + $connection = $this->newActiveConnection(['public-channel']); + + $message = new Mocks\Message([ + 'appId' => '1234', + 'serverId' => 'different_server_id', + 'event' => 'some-event', + 'data' => [ + 'channel' => 'public-channel', + 'test' => 'yes', + ], + ]); + + $this->channelManager->onMessage( + $this->channelManager->getRedisKey('1234', 'public-channel'), + $message->getPayload() + ); + + // The message does not contain appId and serverId anymore. + $message = new Mocks\Message([ + 'event' => 'some-event', + 'data' => [ + 'channel' => 'public-channel', + 'test' => 'yes', + ], + ]); + + $connection->assertSentEvent('some-event', $message->getPayloadAsArray()); + } + + public function test_events_get_replicated_across_connections_for_public_channels() + { + $this->runOnlyOnRedisReplication(); + + $connection = $this->newActiveConnection(['public-channel']); + $receiver = $this->newActiveConnection(['public-channel']); + + $message = new Mocks\Message([ + 'appId' => '1234', + 'serverId' => $this->channelManager->getServerId(), + 'event' => 'some-event', + 'data' => [ + 'channel' => 'public-channel', + 'test' => 'yes', + ], + 'socketId' => $connection->socketId, + ]); + + $channel = $this->channelManager->find('1234', 'public-channel'); + + $channel->broadcastToEveryoneExcept( + $message->getPayloadAsObject(), $connection->socketId, '1234', true + ); + + $receiver->assertSentEvent('some-event', $message->getPayloadAsArray()); + + $this->getSubscribeClient() + ->assertNothingDispatched(); + + $this->getPublishClient() + ->assertCalledWithArgs('publish', [ + $this->channelManager->getRedisKey('1234', 'public-channel'), + $message->getPayload(), + ]); + } } diff --git a/tests/ReplicationTest.php b/tests/ReplicationTest.php index b7dacba..30ef045 100644 --- a/tests/ReplicationTest.php +++ b/tests/ReplicationTest.php @@ -2,8 +2,6 @@ namespace BeyondCode\LaravelWebSockets\Test; -use Carbon\Carbon; - class ReplicationTest extends TestCase { /** @@ -25,345 +23,14 @@ class ReplicationTest extends TestCase ->assertCalledWithArgs('subscribe', [$this->channelManager->getRedisKey('1234', 'public-channel')]); } - public function test_events_get_replicated_across_connections_for_public_channels() - { - $connection = $this->newActiveConnection(['public-channel']); - $receiver = $this->newActiveConnection(['public-channel']); - - $message = new Mocks\Message([ - 'appId' => '1234', - 'serverId' => $this->channelManager->getServerId(), - 'event' => 'some-event', - 'data' => [ - 'channel' => 'public-channel', - 'test' => 'yes', - ], - 'socketId' => $connection->socketId, - ]); - - $channel = $this->channelManager->find('1234', 'public-channel'); - - $channel->broadcastToEveryoneExcept( - $message->getPayloadAsObject(), $connection->socketId, '1234', true - ); - - $receiver->assertSentEvent('some-event', $message->getPayloadAsArray()); - - $this->getSubscribeClient() - ->assertNothingDispatched(); - - $this->getPublishClient() - ->assertCalledWithArgs('publish', [ - $this->channelManager->getRedisKey('1234', 'public-channel'), - $message->getPayload(), - ]); - } - - public function test_events_get_replicated_across_connections_for_private_channels() - { - $connection = $this->newPrivateConnection('private-channel'); - $receiver = $this->newPrivateConnection('private-channel'); - - $message = new Mocks\SignedMessage([ - 'appId' => '1234', - 'serverId' => $this->channelManager->getServerId(), - 'event' => 'some-event', - 'data' => [ - 'channel' => 'private-channel', - 'test' => 'yes', - ], - 'socketId' => $connection->socketId, - ], $connection, 'private-channel'); - - $channel = $this->channelManager->find('1234', 'private-channel'); - - $channel->broadcastToEveryoneExcept( - $message->getPayloadAsObject(), $connection->socketId, '1234', true - ); - - $receiver->assertSentEvent('some-event', $message->getPayloadAsArray()); - - $this->getSubscribeClient() - ->assertNothingDispatched(); - - $this->getPublishClient() - ->assertCalledWithArgs('publish', [ - $this->channelManager->getRedisKey('1234', 'private-channel'), - $message->getPayload(), - ]); - } - - public function test_events_get_replicated_across_connections_for_presence_channels() - { - $connection = $this->newPresenceConnection('presence-channel'); - $receiver = $this->newPresenceConnection('presence-channel', ['user_id' => 2]); - - $user = [ - 'user_id' => 1, - 'user_info' => [ - 'name' => 'Rick', - ], - ]; - - $encodedUser = json_encode($user); - - $message = new Mocks\SignedMessage([ - 'appId' => '1234', - 'serverId' => $this->channelManager->getServerId(), - 'event' => 'some-event', - 'data' => [ - 'channel' => 'presence-channel', - 'channel_data' => $encodedUser, - 'test' => 'yes', - ], - 'socketId' => $connection->socketId, - ], $connection, 'presence-channel', $encodedUser); - - $channel = $this->channelManager->find('1234', 'presence-channel'); - - $channel->broadcastToEveryoneExcept( - $message->getPayloadAsObject(), $connection->socketId, '1234', true - ); - - $receiver->assertSentEvent('some-event', $message->getPayloadAsArray()); - - $this->getSubscribeClient() - ->assertNothingDispatched(); - - $this->getPublishClient() - ->assertCalledWithArgs('publish', [ - $this->channelManager->getRedisKey('1234', 'presence-channel'), - $message->getPayload(), - ]); - } - - public function test_not_ponged_connections_do_get_removed_for_public_channels() - { - $activeConnection = $this->newActiveConnection(['public-channel']); - $obsoleteConnection = $this->newActiveConnection(['public-channel']); - - // The active connection just pinged, it should not be closed. - $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); - - // Make the connection look like it was lost 1 day ago. - $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'public-channel') - ->then(function ($count) { - $this->assertEquals(2, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(1, $expiredConnections); - }); - - $this->channelManager->removeObsoleteConnections(); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'public-channel') - ->then(function ($count) { - $this->assertEquals(1, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(0, $expiredConnections); - }); - } - - public function test_not_ponged_connections_do_get_removed_for_private_channels() - { - $activeConnection = $this->newPrivateConnection('private-channel'); - $obsoleteConnection = $this->newPrivateConnection('private-channel'); - - // The active connection just pinged, it should not be closed. - $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); - - // Make the connection look like it was lost 1 day ago. - $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'private-channel') - ->then(function ($count) { - $this->assertEquals(2, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(1, $expiredConnections); - }); - - $this->channelManager->removeObsoleteConnections(); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'private-channel') - ->then(function ($count) { - $this->assertEquals(1, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(0, $expiredConnections); - }); - } - - public function test_not_ponged_connections_do_get_removed_for_presence_channels() - { - $activeConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 1]); - $obsoleteConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 2]); - - // The active connection just pinged, it should not be closed. - $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); - - // Make the connection look like it was lost 1 day ago. - $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'presence-channel') - ->then(function ($count) { - $this->assertEquals(2, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(1, $expiredConnections); - }); - - $this->channelManager - ->getChannelMembers('1234', 'presence-channel') - ->then(function ($members) { - $this->assertCount(2, $members); - }); - - $this->channelManager->removeObsoleteConnections(); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'presence-channel') - ->then(function ($count) { - $this->assertEquals(1, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(0, $expiredConnections); - }); - - $this->channelManager - ->getChannelMembers('1234', 'presence-channel') - ->then(function ($members) { - $this->assertCount(1, $members); - }); - } - - public function test_events_are_processed_by_on_message_on_public_channels() + public function test_unsubscribe_from_topic_when_the_last_connection_leaves() { $connection = $this->newActiveConnection(['public-channel']); - $message = new Mocks\Message([ - 'appId' => '1234', - 'serverId' => 'different_server_id', - 'event' => 'some-event', - 'data' => [ - 'channel' => 'public-channel', - 'test' => 'yes', - ], - ]); + $this->pusherServer->onClose($connection); - $this->channelManager->onMessage( - $this->channelManager->getRedisKey('1234', 'public-channel'), - $message->getPayload() - ); - - // The message does not contain appId and serverId anymore. - $message = new Mocks\Message([ - 'event' => 'some-event', - 'data' => [ - 'channel' => 'public-channel', - 'test' => 'yes', - ], - ]); - - $connection->assertSentEvent('some-event', $message->getPayloadAsArray()); - } - - public function test_events_are_processed_by_on_message_on_private_channels() - { - $connection = $this->newPrivateConnection('private-channel'); - - $message = new Mocks\SignedMessage([ - 'appId' => '1234', - 'serverId' => 'different_server_id', - 'event' => 'some-event', - 'data' => [ - 'channel' => 'private-channel', - 'test' => 'yes', - ], - ], $connection, 'private-channel'); - - $this->channelManager->onMessage( - $this->channelManager->getRedisKey('1234', 'private-channel'), - $message->getPayload() - ); - - // The message does not contain appId and serverId anymore. - $message = new Mocks\SignedMessage([ - 'event' => 'some-event', - 'data' => [ - 'channel' => 'private-channel', - 'test' => 'yes', - ], - ], $connection, 'private-channel'); - - $connection->assertSentEvent('some-event', $message->getPayloadAsArray()); - } - - public function test_events_are_processed_by_on_message_on_presence_channels() - { - $user = [ - 'user_id' => 1, - 'user_info' => [ - 'name' => 'Rick', - ], - ]; - - $connection = $this->newPresenceConnection('presence-channel', $user); - - $encodedUser = json_encode($user); - - $message = new Mocks\SignedMessage([ - 'appId' => '1234', - 'serverId' => 'different_server_id', - 'event' => 'some-event', - 'data' => [ - 'channel' => 'presence-channel', - 'channel_data' => $encodedUser, - 'test' => 'yes', - ], - ], $connection, 'presence-channel', $encodedUser); - - $this->channelManager->onMessage( - $this->channelManager->getRedisKey('1234', 'presence-channel'), - $message->getPayload() - ); - - // The message does not contain appId and serverId anymore. - $message = new Mocks\SignedMessage([ - 'event' => 'some-event', - 'data' => [ - 'channel' => 'presence-channel', - 'channel_data' => $encodedUser, - 'test' => 'yes', - ], - ], $connection, 'presence-channel', $encodedUser); - - $connection->assertSentEvent('some-event', $message->getPayloadAsArray()); + $this->getSubscribeClient() + ->assertCalledWithArgs('unsubscribe', [$this->channelManager->getRedisKey('1234')]) + ->assertCalledWithArgs('unsubscribe', [$this->channelManager->getRedisKey('1234', 'public-channel')]); } }