Skip to content

Commit

Permalink
Test listener integration
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 5, 2024
1 parent 6addec8 commit 57cdbfb
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/test/php/websocket/unittest/WebSocketTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use peer\{Socket, ProtocolException};
use test\{Assert, Expect, Test, Values};
use util\Bytes;
use websocket\WebSocket;
use websocket\{WebSocket, Listener};

class WebSocketTest {

Expand Down Expand Up @@ -173,4 +173,21 @@ public function pings_are_answered() {
$fixture->socket()->out
);
}

#[Test]
public function listening() {
$listener= new class() extends Listener {
public $events= [];
public function open($conn) { $this->events[]= 'open'; }
public function message($conn, $message) { $this->events[]= "message<{$message}>"; }
public function close($conn) { $this->events[]= 'close'; }
};

$fixture= $this->fixture("\x81\x04Test")->listening($listener);
$fixture->connect();
iterator_to_array($fixture->receive());
$fixture->close();

Assert::equals(['open', 'message<Test>', 'close'], $listener->events);
}
}

0 comments on commit 57cdbfb

Please sign in to comment.