From bbfaa4628aae712f73799bb4b8dc0bbe74b46038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20J=2E=20Garc=C3=ADa=20Lagar?= Date: Wed, 10 Feb 2016 21:00:50 +0100 Subject: [PATCH] Fix `Stream::read($length)` implementation When `$length` value exceeds the stream eof, the remaining stream content must be returned. --- src/Stream.php | 4 ---- tests/StreamTest.php | 10 ++++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Stream.php b/src/Stream.php index 062e784..9f5677f 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -163,10 +163,6 @@ public function read($length) return fread($this->socket, $length); } - if ($this->getSize() < ($this->readed + $length)) { - throw new StreamException('Cannot read more than %s', $this->getSize() - $this->readed); - } - if ($this->getSize() === $this->readed) { return ''; } diff --git a/tests/StreamTest.php b/tests/StreamTest.php index 09bc7ee..9d5ea10 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -144,4 +144,14 @@ public function testClose() $this->assertFalse(is_resource($socket)); } + + public function testRead() + { + $stream = $this->createSocket("Body"); + + $this->assertEquals("Bod", $stream->read(3)); + $this->assertEquals("y", $stream->read(3)); + + $stream->close(); + } }