Skip to content

Commit

Permalink
Test ping and close handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 19, 2025
1 parent c2fd23b commit 7e1d2fa
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/test/php/web/unittest/server/WebsocketProtocolTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,48 @@ public function receive_binary_message() {
}

#[Test]
public function answer_text_message() {
$out= $this->handle(["\x81\x04", "Test"], function($conn, $message) use(&$received) {
public function send_messages() {
$out= $this->handle(["\x81\x04", "Test"], function($conn, $message) {
$conn->send('Re: '.$message);
$conn->send(new Bytes("\x47\x11"));
});

Assert::equals(["\x81\x08Re: Test"], $out);
Assert::equals(["\x81\x08Re: Test", "\x82\x02\x47\x11"], $out);
}

#[Test]
public function answers_ping_with_pong_automatically() {
$out= $this->handle(["\x89\x04", "Test"], function($conn, $message) {
// NOOP
});

Assert::equals(["\x8a\x04Test"], $out);
}

#[Test]
public function default_close() {
$out= $this->handle(["\x88\x00"], function($conn, $message) {
// NOOP
});

Assert::equals(["\x88\x02\x03\xe8"], $out);
}

#[Test]
public function answer_with_client_code_and_reason() {
$out= $this->handle(["\x88\x06", "\x03\xe8Test"], function($conn, $message) {
// NOOP
});

Assert::equals(["\x88\x06\x03\xe8Test"], $out);
}

#[Test]
public function protocol_error() {
$out= $this->handle(["\x88\x02", "\x03\xf7"], function($conn, $message) {
// NOOP
});

Assert::equals(["\x88\x02\x03\xea"], $out);
}
}

0 comments on commit 7e1d2fa

Please sign in to comment.