Skip to content

Commit e5a1ec0

Browse files
committed
PHP 8.2 fix
1 parent 271831e commit e5a1ec0

7 files changed

+109
-47
lines changed

lib/Connection.php

-45
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,6 @@ public function getCloseStatus(): ?int
6161
return $this->close_status;
6262
}
6363

64-
/**
65-
* Convenience method to send text message
66-
* @param string $payload Content as string
67-
*/
68-
public function text(string $payload): void
69-
{
70-
$message = $this->msg_factory->create('text', $payload);
71-
$this->pushMessage($message);
72-
}
73-
74-
/**
75-
* Convenience method to send binary message
76-
* @param string $payload Content as binary string
77-
*/
78-
public function binary(string $payload): void
79-
{
80-
$message = $this->msg_factory->create('binary', $payload);
81-
$this->pushMessage($message);
82-
}
83-
84-
/**
85-
* Convenience method to send ping
86-
* @param string $payload Optional text as string
87-
*/
88-
public function ping(string $payload = ''): void
89-
{
90-
$message = $this->msg_factory->create('ping', $payload);
91-
$this->pushMessage($message);
92-
}
93-
94-
/**
95-
* Convenience method to send unsolicited pong
96-
* @param string $payload Optional text as string
97-
*/
98-
public function pong(string $payload = ''): void
99-
{
100-
$message = $this->msg_factory->create('pong', $payload);
101-
$this->pushMessage($message);
102-
}
103-
10464
/**
10565
* Tell the socket to close.
10666
*
@@ -357,11 +317,6 @@ private function autoRespond(array $frame)
357317

358318
/* ---------- Stream I/O methods ------------------------------------------------- */
359319

360-
public function getStream()
361-
{
362-
return $this->isConnected() ? $this->stream : null;
363-
}
364-
365320
/**
366321
* Close connection stream.
367322
* @return bool

lib/Message/Message.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public function __toString(): string
6161
// Split messages into frames
6262
public function getFrames(bool $masked = true, int $framesize = 4096): array
6363
{
64+
6465
$frames = [];
65-
foreach (str_split($this->getContent(), $framesize) as $payload) {
66+
$split = str_split($this->getContent(), $framesize) ?: [''];
67+
foreach ($split as $payload) {
6668
$frames[] = [false, $payload, 'continuation', $masked];
6769
}
6870
$frames[0][2] = $this->opcode;

phpunit.xml.dist

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
convertDeprecationsToExceptions="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
11+
>
312
<coverage>
413
<include>
514
<directory suffix=".php">lib/</directory>

tests/ClientTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,11 @@ public function testUnconnectedClient(): void
512512
$this->assertNull($client->getRemoteName());
513513
$this->assertNull($client->getCloseStatus());
514514
}
515+
516+
public function testDeprecated(): void
517+
{
518+
$client = new Client('ws://localhost:8000/my/mock/path');
519+
$this->expectDeprecation();
520+
$this->assertNull($client->getPier());
521+
}
515522
}

tests/ServerTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,37 @@ public function testUnconnectedServer(): void
458458
$this->assertNull($server->getCloseStatus());
459459
$this->assertTrue(MockSocket::isEmpty());
460460
}
461+
462+
public function testFailedHandshake(): void
463+
{
464+
MockSocket::initialize('server.construct', $this);
465+
$server = new Server();
466+
$this->assertTrue(MockSocket::isEmpty());
467+
468+
MockSocket::initialize('server.accept-failed-handshake', $this);
469+
$server->accept();
470+
$this->expectException('WebSocket\ConnectionException');
471+
$this->expectExceptionCode(0);
472+
$this->expectExceptionMessage('Could not read from stream');
473+
$server->send('Connect');
474+
$this->assertFalse($server->isConnected());
475+
$this->assertTrue(MockSocket::isEmpty());
476+
}
477+
478+
public function testServerDisconnect(): void
479+
{
480+
MockSocket::initialize('server.construct', $this);
481+
$server = new Server();
482+
$this->assertTrue(MockSocket::isEmpty());
483+
MockSocket::initialize('server.accept', $this);
484+
$server->accept();
485+
$server->send('Connect');
486+
$this->assertTrue($server->isConnected());
487+
$this->assertTrue(MockSocket::isEmpty());
488+
489+
MockSocket::initialize('server.disconnect', $this);
490+
$server->disconnect();
491+
$this->assertFalse($server->isConnected());
492+
$this->assertTrue(MockSocket::isEmpty());
493+
}
461494
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"function": "stream_socket_accept",
4+
"params": [
5+
"@mock-socket"
6+
],
7+
"return": "@mock-stream"
8+
},
9+
{
10+
"function": "stream_socket_get_name",
11+
"params": [
12+
"@mock-stream"
13+
],
14+
"return": "127.0.0.1:12345"
15+
},
16+
{
17+
"function": "stream_get_line",
18+
"params": [
19+
"@mock-stream",
20+
1024,
21+
"\r\n"
22+
],
23+
"return": false
24+
},
25+
{
26+
"function": "get_resource_type",
27+
"params": [
28+
"@mock-stream"
29+
],
30+
"return": ""
31+
}
32+
]

tests/scripts/server.disconnect.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
3+
{
4+
"function": "get_resource_type",
5+
"params": [
6+
"@mock-stream"
7+
],
8+
"return": "stream"
9+
},
10+
{
11+
"function": "fclose",
12+
"params": [
13+
"@mock-stream"
14+
],
15+
"return": true
16+
},
17+
{
18+
"function": "get_resource_type",
19+
"params": [
20+
"@mock-stream"
21+
],
22+
"return": ""
23+
}
24+
]

0 commit comments

Comments
 (0)