/** * If the given message owns the passed in resource, then * read data on that message. * * @param Message $message * @param resource $resource * @return void */ protected function readResource(Message $message, $resource) { if ($message->getResource() === $resource) { $message->receive(); } }
it('should read until no more content', function () { $message = new Message($this->resource, 1); fwrite($this->resource, "hello world"); fseek($this->resource, 0); $message->receive(); expect($message->getContent())->to->equal('hello world'); }); it('should emit a data event when data is received', function () { $message = new Message($this->resource, 1); fwrite($this->resource, "hello world"); fseek($this->resource, 0); $content = ''; $message->on('data', function ($data) use(&$content) { $content .= $data; }); $message->receive(); expect($content)->to->equal('hello world'); }); it('should flag the message as readable', function () { $this->message->receive(); expect($this->message->isReadable())->to->be->true; }); it('should not allow reading from a writable message', function () { $this->message->write('hello'); expect([$this->message, 'receive'])->to->throw('RuntimeException'); }); it('should emit an end event when a terminate string is read', function () { $message = null; $this->message->on('end', function ($msg) use(&$message) { $message = $msg; });