From a058259ec799d6e27ce6d9f6b793a1f5d19bcabe Mon Sep 17 00:00:00 2001 From: kirills-morozovs <94073530+kirills-morozovs@users.noreply.github.com> Date: Fri, 27 Dec 2024 23:05:09 +0200 Subject: [PATCH] Check if channel variable isn't null when passed as a filter on channels() method in ArrayChannelManager (#292) Co-authored-by: Joe Dixon --- .../Pusher/Managers/ArrayChannelManager.php | 2 +- tests/Unit/Protocols/Pusher/EventTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Protocols/Pusher/Managers/ArrayChannelManager.php b/src/Protocols/Pusher/Managers/ArrayChannelManager.php index f1c16c3c..8536d783 100644 --- a/src/Protocols/Pusher/Managers/ArrayChannelManager.php +++ b/src/Protocols/Pusher/Managers/ArrayChannelManager.php @@ -134,7 +134,7 @@ public function channels(?string $channel = null): Channel|array|null { $channels = $this->applications[$this->application->id()] ?? []; - if ($channel) { + if (isset($channel)) { return $channels[$channel] ?? null; } diff --git a/tests/Unit/Protocols/Pusher/EventTest.php b/tests/Unit/Protocols/Pusher/EventTest.php index 4d86d7d0..1128ae89 100644 --- a/tests/Unit/Protocols/Pusher/EventTest.php +++ b/tests/Unit/Protocols/Pusher/EventTest.php @@ -38,6 +38,19 @@ ]); }); +it('can subscribe to an empty channel', function () { + $this->pusher->handle( + $this->connection, + 'pusher:subscribe', + ['channel' => ''] + ); + + $this->connection->assertReceived([ + 'event' => 'pusher_internal:subscription_succeeded', + 'data' => '{}', + ]); +}); + it('can unsubscribe from a channel', function () { $this->pusher->handle( $this->connection,