Skip to content

Commit

Permalink
Adjust tests to socket not being closed by Connection
Browse files Browse the repository at this point in the history
This is now handled inside the Messages protocol implementation
  • Loading branch information
thekid committed Oct 4, 2024
1 parent 91fe303 commit d990960
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/test/php/websocket/unittest/ConnectionTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,21 @@ public function fragmented_text_with_ping_inbetween() {
}

#[Test, Values(['', "\x81"])]
public function closes_connection_on_invalid_packet($bytes) {
$channel= (new Channel($bytes))->connect();
$this->receive($channel);

Assert::equals('', $channel->out);
Assert::false($channel->isConnected(), 'Channel closed');
public function closes_connection_on_empty_packet($bytes) {
$received= $this->receive(new Channel($bytes));
Assert::equals([], $received);
}

#[Test]
public function closes_connection_on_invalid_opcode() {
$channel= (new Channel("\x8f\x00"))->connect();
$this->receive($channel);

// 0x80 | 0x08 (CLOSE), 2 bytes, pack("n", 1002)
Assert::equals("\x88\x02\x03\xea", $channel->out);
Assert::false($channel->isConnected(), 'Channel closed');
$received= $this->receive(new Channel("\x8f\x00"));
Assert::equals([[Opcodes::CLOSE => pack('n', 1002)]], $received);
}

#[Test]
public function closes_connection_when_exceeding_max_length() {
$channel= (new Channel("\x81\x7f".pack('J', Connection::MAXLENGTH + 1)))->connect();
$this->receive($channel);

// 0x80 | 0x08 (CLOSE), 2 bytes, pack("n", 1003)
Assert::equals("\x88\x02\x03\xeb", $channel->out);
Assert::false($channel->isConnected(), 'Channel closed');
$received= $this->receive(new Channel("\x81\x7f".pack('J', Connection::MAXLENGTH + 1)));
Assert::equals([[Opcodes::CLOSE => pack('n', 1003)]], $received);
}

#[Test]
Expand Down

0 comments on commit d990960

Please sign in to comment.