on("data", function ($v) use (&$written) { $written = $v; }); $stream->send(["helloworld"]); $this->assertEquals("helloworld\n", $written); $cs->close(); } public function testReceivingFrames() { $is = new ThroughStream(); $os = new ThroughStream(); $cs = new CompositeStream($is, $os); $ws = new CompositeStream($os, $is); $proto = new LineProtocol(); $stream = new ProtocolStream($cs, $proto); $read = null; $stream->on("message", function ($v) use (&$read) { $read = $v; }); $ws->write("helloworld\n"); $this->assertEquals([ "helloworld" ], $read); $cs->close(); } public function testPartialFrames() { $is = new ThroughStream(); $os = new ThroughStream(); $cs = new CompositeStream($is, $os); $ws = new CompositeStream($os, $is); $proto = new JsonProtocol( frameSeparator: "\n" ); $stream = new ProtocolStream($cs, $proto); $read = null; $stream->on("message", function ($v) use (&$read) { $read = $v; }); $ws->write('{"hello":'); $ws->write('"world"}'); $ws->write("\n"); $this->assertEquals([ "hello" => "world" ], $read); $cs->close(); } }