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

Commit ce652bb

Browse files
committed
Mocked message expects array
1 parent b5f081c commit ce652bb

10 files changed

+75
-57
lines changed

tests/Channels/ChannelReplicationTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public function replication_clients_can_subscribe_to_channels()
2222
{
2323
$connection = $this->getWebSocketConnection();
2424

25-
$message = new Message(json_encode([
25+
$message = new Message([
2626
'event' => 'pusher:subscribe',
2727
'data' => [
2828
'channel' => 'basic-channel',
2929
],
30-
]));
30+
]);
3131

3232
$this->pusherServer->onOpen($connection);
3333

@@ -47,12 +47,12 @@ public function replication_clients_can_unsubscribe_from_channels()
4747

4848
$this->assertTrue($channel->hasConnections());
4949

50-
$message = new Message(json_encode([
50+
$message = new Message([
5151
'event' => 'pusher:unsubscribe',
5252
'data' => [
5353
'channel' => 'test-channel',
5454
],
55-
]));
55+
]);
5656

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

@@ -67,7 +67,7 @@ public function replication_a_client_cannot_broadcast_to_other_clients_by_defaul
6767

6868
$connection = $this->getConnectedWebSocketConnection(['test-channel']);
6969

70-
$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');
70+
$message = new Message(['event' => 'client-test', 'data' => [], 'channel' => 'test-channel']);
7171

7272
$this->pusherServer->onMessage($connection, $message);
7373

@@ -84,7 +84,7 @@ public function replication_a_client_can_be_enabled_to_broadcast_to_other_client
8484

8585
$connection = $this->getConnectedWebSocketConnection(['test-channel']);
8686

87-
$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');
87+
$message = new Message(['event' => 'client-test', 'data' => [], 'channel' => 'test-channel']);
8888

8989
$this->pusherServer->onMessage($connection, $message);
9090

@@ -147,9 +147,9 @@ public function replication_it_responds_correctly_to_the_ping_message()
147147
{
148148
$connection = $this->getConnectedWebSocketConnection();
149149

150-
$message = new Message(json_encode([
150+
$message = new Message([
151151
'event' => 'pusher:ping',
152-
]));
152+
]);
153153

154154
$this->pusherServer->onMessage($connection, $message);
155155

tests/Channels/ChannelTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public function clients_can_subscribe_to_channels()
1212
{
1313
$connection = $this->getWebSocketConnection();
1414

15-
$message = new Message(json_encode([
15+
$message = new Message([
1616
'event' => 'pusher:subscribe',
1717
'data' => [
1818
'channel' => 'basic-channel',
1919
],
20-
]));
20+
]);
2121

2222
$this->pusherServer->onOpen($connection);
2323

@@ -37,12 +37,12 @@ public function clients_can_unsubscribe_from_channels()
3737

3838
$this->assertTrue($channel->hasConnections());
3939

40-
$message = new Message(json_encode([
40+
$message = new Message([
4141
'event' => 'pusher:unsubscribe',
4242
'data' => [
4343
'channel' => 'test-channel',
4444
],
45-
]));
45+
]);
4646

4747
$this->pusherServer->onMessage($connection, $message);
4848

@@ -57,7 +57,7 @@ public function a_client_cannot_broadcast_to_other_clients_by_default()
5757

5858
$connection = $this->getConnectedWebSocketConnection(['test-channel']);
5959

60-
$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');
60+
$message = new Message(['event' => 'client-test', 'data' => [], 'channel' => 'test-channel']);
6161

6262
$this->pusherServer->onMessage($connection, $message);
6363

@@ -74,7 +74,7 @@ public function a_client_can_be_enabled_to_broadcast_to_other_clients()
7474

7575
$connection = $this->getConnectedWebSocketConnection(['test-channel']);
7676

77-
$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');
77+
$message = new Message(['event' => 'client-test', 'data' => [], 'channel' => 'test-channel']);
7878

7979
$this->pusherServer->onMessage($connection, $message);
8080

@@ -137,9 +137,9 @@ public function it_responds_correctly_to_the_ping_message()
137137
{
138138
$connection = $this->getConnectedWebSocketConnection();
139139

140-
$message = new Message(json_encode([
140+
$message = new Message([
141141
'event' => 'pusher:ping',
142-
]));
142+
]);
143143

144144
$this->pusherServer->onMessage($connection, $message);
145145

tests/Channels/PresenceChannelReplicationTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels()
3333

3434
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
3535

36-
$message = new Message(json_encode([
36+
$message = new Message([
3737
'event' => 'pusher:subscribe',
3838
'data' => [
3939
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
4040
'channel' => 'presence-channel',
4141
'channel_data' => json_encode($channelData),
4242
],
43-
]));
43+
]);
4444

4545
$this->pusherServer->onMessage($connection, $message);
4646

@@ -67,14 +67,14 @@ public function clients_with_valid_auth_signatures_can_leave_presence_channels()
6767

6868
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
6969

70-
$message = new Message(json_encode([
70+
$message = new Message([
7171
'event' => 'pusher:subscribe',
7272
'data' => [
7373
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
7474
'channel' => 'presence-channel',
7575
'channel_data' => json_encode($channelData),
7676
],
77-
]));
77+
]);
7878

7979
$this->pusherServer->onMessage($connection, $message);
8080

@@ -89,13 +89,13 @@ public function clients_with_valid_auth_signatures_can_leave_presence_channels()
8989
$this->getPublishClient()
9090
->resetAssertions();
9191

92-
$message = new Message(json_encode([
92+
$message = new Message([
9393
'event' => 'pusher:unsubscribe',
9494
'data' => [
9595
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
9696
'channel' => 'presence-channel',
9797
],
98-
]));
98+
]);
9999

100100
$this->pusherServer->onMessage($connection, $message);
101101

@@ -117,14 +117,14 @@ public function clients_with_no_user_info_can_join_presence_channels()
117117

118118
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
119119

120-
$message = new Message(json_encode([
120+
$message = new Message([
121121
'event' => 'pusher:subscribe',
122122
'data' => [
123123
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
124124
'channel' => 'presence-channel',
125125
'channel_data' => json_encode($channelData),
126126
],
127-
]));
127+
]);
128128

129129
$this->pusherServer->onMessage($connection, $message);
130130

tests/Channels/PresenceChannelTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public function clients_need_valid_auth_signatures_to_join_presence_channels()
1515

1616
$connection = $this->getWebSocketConnection();
1717

18-
$message = new Message(json_encode([
18+
$message = new Message([
1919
'event' => 'pusher:subscribe',
2020
'data' => [
2121
'auth' => 'invalid',
2222
'channel' => 'presence-channel',
2323
],
24-
]));
24+
]);
2525

2626
$this->pusherServer->onOpen($connection);
2727

@@ -46,14 +46,14 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels()
4646

4747
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
4848

49-
$message = new Message(json_encode([
49+
$message = new Message([
5050
'event' => 'pusher:subscribe',
5151
'data' => [
5252
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
5353
'channel' => 'presence-channel',
5454
'channel_data' => json_encode($channelData),
5555
],
56-
]));
56+
]);
5757

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

@@ -77,28 +77,28 @@ public function clients_with_valid_auth_signatures_can_leave_presence_channels()
7777

7878
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
7979

80-
$message = new Message(json_encode([
80+
$message = new Message([
8181
'event' => 'pusher:subscribe',
8282
'data' => [
8383
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
8484
'channel' => 'presence-channel',
8585
'channel_data' => json_encode($channelData),
8686
],
87-
]));
87+
]);
8888

8989
$this->pusherServer->onMessage($connection, $message);
9090

9191
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
9292
'channel' => 'presence-channel',
9393
]);
9494

95-
$message = new Message(json_encode([
95+
$message = new Message([
9696
'event' => 'pusher:unsubscribe',
9797
'data' => [
9898
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
9999
'channel' => 'presence-channel',
100100
],
101-
]));
101+
]);
102102

103103
$this->pusherServer->onMessage($connection, $message);
104104
}
@@ -118,14 +118,14 @@ public function clients_with_no_user_info_can_join_presence_channels()
118118

119119
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
120120

121-
$message = new Message(json_encode([
121+
$message = new Message([
122122
'event' => 'pusher:subscribe',
123123
'data' => [
124124
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
125125
'channel' => 'presence-channel',
126126
'channel_data' => json_encode($channelData),
127127
],
128-
]));
128+
]);
129129

130130
$this->pusherServer->onMessage($connection, $message);
131131

@@ -150,13 +150,13 @@ public function clients_with_valid_auth_signatures_cannot_leave_channels_they_ar
150150

151151
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
152152

153-
$message = new Message(json_encode([
153+
$message = new Message([
154154
'event' => 'pusher:unsubscribe',
155155
'data' => [
156156
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
157157
'channel' => 'presence-channel',
158158
],
159-
]));
159+
]);
160160

161161
$this->pusherServer->onMessage($connection, $message);
162162

tests/Channels/PrivateChannelReplicationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function replication_clients_need_valid_auth_signatures_to_join_private_c
2525

2626
$connection = $this->getWebSocketConnection();
2727

28-
$message = new Message(json_encode([
28+
$message = new Message([
2929
'event' => 'pusher:subscribe',
3030
'data' => [
3131
'auth' => 'invalid',
3232
'channel' => 'private-channel',
3333
],
34-
]));
34+
]);
3535

3636
$this->pusherServer->onOpen($connection);
3737

@@ -49,13 +49,13 @@ public function replication_clients_with_valid_auth_signatures_can_join_private_
4949

5050
$hashedAppSecret = hash_hmac('sha256', $signature, $connection->app->secret);
5151

52-
$message = new Message(json_encode([
52+
$message = new Message([
5353
'event' => 'pusher:subscribe',
5454
'data' => [
5555
'auth' => "{$connection->app->key}:{$hashedAppSecret}",
5656
'channel' => 'private-channel',
5757
],
58-
]));
58+
]);
5959

6060
$this->pusherServer->onMessage($connection, $message);
6161

tests/Channels/PrivateChannelTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public function clients_need_valid_auth_signatures_to_join_private_channels()
1515

1616
$connection = $this->getWebSocketConnection();
1717

18-
$message = new Message(json_encode([
18+
$message = new Message([
1919
'event' => 'pusher:subscribe',
2020
'data' => [
2121
'auth' => 'invalid',
2222
'channel' => 'private-channel',
2323
],
24-
]));
24+
]);
2525

2626
$this->pusherServer->onOpen($connection);
2727

@@ -39,13 +39,13 @@ public function clients_with_valid_auth_signatures_can_join_private_channels()
3939

4040
$hashedAppSecret = hash_hmac('sha256', $signature, $connection->app->secret);
4141

42-
$message = new Message(json_encode([
42+
$message = new Message([
4343
'event' => 'pusher:subscribe',
4444
'data' => [
4545
'auth' => "{$connection->app->key}:{$hashedAppSecret}",
4646
'channel' => 'private-channel',
4747
],
48-
]));
48+
]);
4949

5050
$this->pusherServer->onMessage($connection, $message);
5151

tests/ConnectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function ping_returns_pong()
5858
{
5959
$connection = $this->getWebSocketConnection();
6060

61-
$message = new Message('{"event": "pusher:ping"}');
61+
$message = new Message(['event' => 'pusher:ping']);
6262

6363
$this->pusherServer->onOpen($connection);
6464

tests/Messages/PusherClientMessageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public function client_messages_do_not_work_when_disabled()
1212
{
1313
$connection = $this->getConnectedWebSocketConnection(['test-channel']);
1414

15-
$message = new Message(json_encode([
15+
$message = new Message([
1616
'event' => 'client-test',
1717
'channel' => 'test-channel',
1818
'data' => [
1919
'client-event' => 'test',
2020
],
21-
]));
21+
]);
2222

2323
$this->pusherServer->onMessage($connection, $message);
2424

@@ -42,13 +42,13 @@ public function client_messages_get_broadcasted_when_enabled()
4242
$connection1 = $this->getConnectedWebSocketConnection(['test-channel']);
4343
$connection2 = $this->getConnectedWebSocketConnection(['test-channel']);
4444

45-
$message = new Message(json_encode([
45+
$message = new Message([
4646
'event' => 'client-test',
4747
'channel' => 'test-channel',
4848
'data' => [
4949
'client-event' => 'test',
5050
],
51-
]));
51+
]);
5252

5353
$this->pusherServer->onMessage($connection1, $message);
5454

0 commit comments

Comments
 (0)