@@ -31,13 +31,15 @@ public function query($url, $expected) {
31
31
Assert::equals ($ expected , (new WebSocket ($ url ))->path ());
32
32
}
33
33
34
+ /** @deprecated */
34
35
#[Test]
35
36
public function default_origin () {
36
- Assert::equals ( ' localhost ' , (new WebSocket ('ws://example.com ' ))->origin ());
37
+ Assert::null ( (new WebSocket ('ws://example.com ' ))->origin ());
37
38
}
38
39
40
+ /** @deprecated */
39
41
#[Test]
40
- public function origin () {
42
+ public function origin_via_constructor () {
41
43
Assert::equals ('example.com ' , (new WebSocket ('ws://example.com ' , 'example.com ' ))->origin ());
42
44
}
43
45
@@ -47,6 +49,12 @@ public function socket_argument() {
47
49
Assert::equals ($ s , (new WebSocket ($ s ))->socket ());
48
50
}
49
51
52
+ #[Test, Values([[null , '/ ' ], ['/ ' , '/ ' ], ['/sub ' , '/sub ' ], ['/?test=1&l=de ' , '/?test=1&l=de ' ]])]
53
+ public function socket_path ($ path , $ expected ) {
54
+ $ s = new Socket ('example.com ' , 8443 );
55
+ Assert::equals ($ expected , (new WebSocket ($ s , $ path ))->path ());
56
+ }
57
+
50
58
#[Test, Values([['ws://example.com ' , 80 ], ['wss://example.com ' , 443 ]])]
51
59
public function default_port ($ url , $ expected ) {
52
60
Assert::equals ($ expected , (new WebSocket ($ url ))->socket ()->port );
@@ -153,6 +161,41 @@ public function handle_server_error() {
153
161
Assert::false ($ fixture ->connected ());
154
162
}
155
163
164
+ #[Test]
165
+ public function handshake () {
166
+ $ fixture = $ this ->fixture ();
167
+ $ fixture ->connect ();
168
+
169
+ Assert::equals (
170
+ "GET / HTTP/1.1 \r\n" .
171
+ "Upgrade: websocket \r\n" .
172
+ "Sec-WebSocket-Key: KioqKioqKioqKioqKioqKg== \r\n" .
173
+ "Sec-WebSocket-Version: 13 \r\n" .
174
+ "Connection: Upgrade \r\n" .
175
+ "Host: test \r\n\r\n" ,
176
+ $ fixture ->socket ()->out
177
+ );
178
+ }
179
+
180
+ #[Test]
181
+ public function sends_headers () {
182
+ $ fixture = $ this ->fixture ();
183
+ $ fixture ->connect (['Origin ' => 'example.com ' , 'Sec-WebSocket-Protocol ' => ['wamp ' , 'soap ' ]]);
184
+
185
+ Assert::equals (
186
+ "GET / HTTP/1.1 \r\n" .
187
+ "Upgrade: websocket \r\n" .
188
+ "Sec-WebSocket-Key: KioqKioqKioqKioqKioqKg== \r\n" .
189
+ "Sec-WebSocket-Version: 13 \r\n" .
190
+ "Connection: Upgrade \r\n" .
191
+ "Origin: example.com \r\n" .
192
+ "Sec-WebSocket-Protocol: wamp \r\n" .
193
+ "Sec-WebSocket-Protocol: soap \r\n" .
194
+ "Host: test \r\n\r\n" ,
195
+ $ fixture ->socket ()->out
196
+ );
197
+ }
198
+
156
199
#[Test]
157
200
public function send_text () {
158
201
$ fixture = $ this ->fixture ();
@@ -165,8 +208,7 @@ public function send_text() {
165
208
"Sec-WebSocket-Key: KioqKioqKioqKioqKioqKg== \r\n" .
166
209
"Sec-WebSocket-Version: 13 \r\n" .
167
210
"Connection: Upgrade \r\n" .
168
- "Host: test \r\n" .
169
- "Origin: localhost \r\n\r\n" .
211
+ "Host: test \r\n\r\n" .
170
212
"\x81\x84**** \176\117\131\136" ,
171
213
$ fixture ->socket ()->out
172
214
);
@@ -184,8 +226,7 @@ public function send_bytes() {
184
226
"Sec-WebSocket-Key: KioqKioqKioqKioqKioqKg== \r\n" .
185
227
"Sec-WebSocket-Version: 13 \r\n" .
186
228
"Connection: Upgrade \r\n" .
187
- "Host: test \r\n" .
188
- "Origin: localhost \r\n\r\n" .
229
+ "Host: test \r\n\r\n" .
189
230
"\x82\x88**** \155\143\154\022\023\004\004\004" ,
190
231
$ fixture ->socket ()->out
191
232
);
@@ -203,8 +244,7 @@ public function pings_are_answered() {
203
244
"Sec-WebSocket-Key: KioqKioqKioqKioqKioqKg== \r\n" .
204
245
"Sec-WebSocket-Version: 13 \r\n" .
205
246
"Connection: Upgrade \r\n" .
206
- "Host: test \r\n" .
207
- "Origin: localhost \r\n\r\n" .
247
+ "Host: test \r\n\r\n" .
208
248
"\x8a\x81**** \013" ,
209
249
$ fixture ->socket ()->out
210
250
);
0 commit comments