File tree Expand file tree Collapse file tree 4 files changed +139
-0
lines changed Expand file tree Collapse file tree 4 files changed +139
-0
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,7 @@ protected function connect(): void
307
307
308
308
$ host_uri = $ this ->socket_uri
309
309
->withScheme ($ this ->socket_uri ->getScheme () == 'wss ' ? 'ssl ' : 'tcp ' )
310
+ ->withPort ($ this ->socket_uri ->getPort () ?? ($ this ->socket_uri ->getScheme () == 'wss ' ? 443 : 80 ))
310
311
->withPath ('' )
311
312
->withQuery ('' )
312
313
->withFragment ('' )
Original file line number Diff line number Diff line change @@ -82,6 +82,26 @@ public function testClientRelativePath(): void
82
82
$ this ->assertTrue (MockSocket::isEmpty ());
83
83
}
84
84
85
+ public function testClientWsDefaultPort (): void
86
+ {
87
+ MockSocket::initialize ('client.connect-default-port-ws ' , $ this );
88
+ $ uri = new Uri ('ws://localhost ' );
89
+ $ uri = $ uri ->withPath ('my/mock/path ' );
90
+ $ client = new Client ($ uri );
91
+ $ client ->send ('Connect ' );
92
+ $ this ->assertTrue (MockSocket::isEmpty ());
93
+ }
94
+
95
+ public function testClientWssDefaultPort (): void
96
+ {
97
+ MockSocket::initialize ('client.connect-default-port-wss ' , $ this );
98
+ $ uri = new Uri ('wss://localhost ' );
99
+ $ uri = $ uri ->withPath ('my/mock/path ' );
100
+ $ client = new Client ($ uri );
101
+ $ client ->send ('Connect ' );
102
+ $ this ->assertTrue (MockSocket::isEmpty ());
103
+ }
104
+
85
105
public function testClientWithTimeout (): void
86
106
{
87
107
MockSocket::initialize ('client.connect-timeout ' , $ this );
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "function" : " stream_context_create" ,
4
+ "params" : [],
5
+ "return" : " @mock-stream-context"
6
+ },
7
+ {
8
+ "function" : " stream_socket_client" ,
9
+ "params" : [
10
+ " tcp:\/\/ localhost:80" ,
11
+ null ,
12
+ null ,
13
+ 5 ,
14
+ 4 ,
15
+ " @mock-stream-context"
16
+ ],
17
+ "return" : " @mock-stream"
18
+ },
19
+ {
20
+ "function" : " get_resource_type" ,
21
+ "params" : [
22
+ " @mock-stream"
23
+ ],
24
+ "return" : " stream"
25
+ },
26
+ {
27
+ "function" : " stream_set_timeout" ,
28
+ "params" : [
29
+ " @mock-stream" ,
30
+ 5
31
+ ],
32
+ "return" : true
33
+ },
34
+ {
35
+ "function" : " fwrite" ,
36
+ "params" : [
37
+ " @mock-stream" ,
38
+ " GET /my/mock/path HTTP/1.1\r\n Host: localhost:80\r\n User-Agent: websocket-client-php\r\n Connection: Upgrade\r\n Upgrade: websocket\r\n Sec-WebSocket-Key: {key}\r\n Sec-WebSocket-Version: 13\r\n\r\n "
39
+ ],
40
+ "input-op" : " key-save" ,
41
+ "return" : 224
42
+ },
43
+ {
44
+ "function" : " fgets" ,
45
+ "params" : [
46
+ " @mock-stream" ,
47
+ 1024
48
+ ],
49
+ "return-op" : " key-respond" ,
50
+ "return" : " HTTP\/ 1.1 101 Switching Protocols\r\n Upgrade: websocket\r\n Connection: Upgrade\r\n Sec-WebSocket-Accept: {key}\r\n\r\n "
51
+ },
52
+ {
53
+ "function" : " fwrite" ,
54
+ "params" : [
55
+ " @mock-stream"
56
+ ],
57
+ "return" : 13
58
+ }
59
+ ]
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "function" : " stream_context_create" ,
4
+ "params" : [],
5
+ "return" : " @mock-stream-context"
6
+ },
7
+ {
8
+ "function" : " stream_socket_client" ,
9
+ "params" : [
10
+ " ssl:\/\/ localhost:443" ,
11
+ null ,
12
+ null ,
13
+ 5 ,
14
+ 4 ,
15
+ " @mock-stream-context"
16
+ ],
17
+ "return" : " @mock-stream"
18
+ },
19
+ {
20
+ "function" : " get_resource_type" ,
21
+ "params" : [
22
+ " @mock-stream"
23
+ ],
24
+ "return" : " stream"
25
+ },
26
+ {
27
+ "function" : " stream_set_timeout" ,
28
+ "params" : [
29
+ " @mock-stream" ,
30
+ 5
31
+ ],
32
+ "return" : true
33
+ },
34
+ {
35
+ "function" : " fwrite" ,
36
+ "params" : [
37
+ " @mock-stream" ,
38
+ " GET /my/mock/path HTTP/1.1\r\n Host: localhost:443\r\n User-Agent: websocket-client-php\r\n Connection: Upgrade\r\n Upgrade: websocket\r\n Sec-WebSocket-Key: {key}\r\n Sec-WebSocket-Version: 13\r\n\r\n "
39
+ ],
40
+ "input-op" : " key-save" ,
41
+ "return" : 224
42
+ },
43
+ {
44
+ "function" : " fgets" ,
45
+ "params" : [
46
+ " @mock-stream" ,
47
+ 1024
48
+ ],
49
+ "return-op" : " key-respond" ,
50
+ "return" : " HTTP\/ 1.1 101 Switching Protocols\r\n Upgrade: websocket\r\n Connection: Upgrade\r\n Sec-WebSocket-Accept: {key}\r\n\r\n "
51
+ },
52
+ {
53
+ "function" : " fwrite" ,
54
+ "params" : [
55
+ " @mock-stream"
56
+ ],
57
+ "return" : 13
58
+ }
59
+ ]
You can’t perform that action at this time.
0 commit comments