handleSubscription() recorded the socket in $channel_connections and in the
buffered ws_channel_connections_* / ws_active_channels cache before
$channel->subscribe() ran, and swallowed the InvalidSignature it threw. On
the same frame shouldRejectMessage() found the entry and called
saveConnection(), and the client got "websocket.subscribe:response Success".
One subscribe with a bad signature put the socket on the private or presence
channel, where it received broadcasts, and WebsocketService listed it.
- Track the socket only after subscribe() succeeds (or it is already on the
channel).
- A failed private/presence subscribe answers "<event>:error" with the
exception's message and code (Invalid Signature, 4009), drops any earlier
tracking of the socket on that channel, takes it off the channel if the
subscribe had already saved it, and ends the frame before
shouldRejectMessage() and the Success reply.
- Public channels behave as before.
Tests assert, after the single subscribe frame, the error reply, no channel
membership, no $channel_connections entry and no cache listing, and that a
later message on the channel does not resubscribe the socket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Introduced `helpers-and-testing.md` to document global helpers and WebsocketService class usage.
- Created `HandlerLifecycleTest.php` to test the full WebSocket handler lifecycle, including connection management, channel subscriptions, and message routing.
- Added `WebsocketServiceTest.php` to validate state tracking methods in WebsocketService, covering user authentication, channel tracking, and broadcast functionality.