Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 50f0b70

Browse files
committed
wip
1 parent 25694c7 commit 50f0b70

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

tests/Channels/PresenceChannelReplicationTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,54 @@ public function setUp(): void
1515

1616
$this->runOnlyOnRedisReplication();
1717
}
18+
19+
/** @test */
20+
public function clients_with_valid_auth_signatures_can_join_presence_channels()
21+
{
22+
$connection = $this->getWebSocketConnection();
23+
24+
$this->pusherServer->onOpen($connection);
25+
26+
$channelData = [
27+
'user_id' => 1,
28+
'user_info' => [
29+
'name' => 'Marcel',
30+
],
31+
];
32+
33+
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
34+
35+
$message = new Message(json_encode([
36+
'event' => 'pusher:subscribe',
37+
'data' => [
38+
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
39+
'channel' => 'presence-channel',
40+
'channel_data' => json_encode($channelData),
41+
],
42+
]));
43+
44+
$this->pusherServer->onMessage($connection, $message);
45+
46+
$this->getPublishClient()
47+
->assertCalledWithArgs('hset', [
48+
'1234:presence-channel',
49+
$connection->socketId,
50+
json_encode($channelData),
51+
])
52+
->assertCalledWithArgs('hgetall', [
53+
'1234:presence-channel'
54+
]);
55+
// TODO: This fails somehow
56+
// Debugging shows the exact same pattern as good.
57+
/* ->assertCalledWithArgs('publish', [
58+
'1234:presence-channel',
59+
json_encode([
60+
'event' => 'pusher_internal:member_added',
61+
'channel' => 'presence-channel',
62+
'data' => $channelData,
63+
'appId' => '1234',
64+
'serverId' => $this->app->make(ReplicationInterface::class)->getServerId(),
65+
]),
66+
]) */
67+
}
1868
}

tests/Channels/PresenceChannelTest.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,9 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels()
5656

5757
$this->pusherServer->onMessage($connection, $message);
5858

59-
$this->getPublishClient()
60-
->assertCalledWithArgs('hset', [
61-
'1234:presence-channel',
62-
$connection->socketId,
63-
json_encode($channelData),
64-
])
65-
->assertCalledWithArgs('hgetall', [
66-
'1234:presence-channel'
67-
]);
68-
// TODO: This fails somehow
69-
// Debugging shows the exact same pattern as good.
70-
/* ->assertCalledWithArgs('publish', [
71-
'1234:presence-channel',
72-
json_encode([
73-
'event' => 'pusher_internal:member_added',
74-
'channel' => 'presence-channel',
75-
'data' => $channelData,
76-
'appId' => '1234',
77-
'serverId' => $this->app->make(ReplicationInterface::class)->getServerId(),
78-
]),
79-
]) */
59+
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
60+
'channel' => 'presence-channel',
61+
]);
8062
}
8163

8264
/** @test */

tests/HttpApi/FetchChannelReplicationTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ public function replication_it_returns_presence_channel_information()
103103

104104
$this->getSubscribeClient()->assertNothingCalled();
105105

106-
dd($this->getSubscribeClient());
107-
108106
$this->getPublishClient()
109107
->assertCalled('hset')
110108
->assertCalled('hgetall');

0 commit comments

Comments
 (0)