diff --git a/CHANGELOG.md b/CHANGELOG.md index 759bdbf..2a761d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## Unreleased + +### Fixed + +- `Stream::create` with a string needs to rewind the created memory stream. + ## 1.4.0 ### Removed diff --git a/src/Stream.php b/src/Stream.php index bcc59ba..fee0c63 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -71,6 +71,7 @@ public static function create($body = ''): StreamInterface if (\is_string($body)) { $resource = \fopen('php://temp', 'rw+'); \fwrite($resource, $body); + \rewind($resource); $body = $resource; } diff --git a/tests/StreamTest.php b/tests/StreamTest.php index 74898e9..d3ac5aa 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -44,6 +44,13 @@ public function testConvertsToString() $stream->close(); } + public function testBuildFromString() + { + $stream = Stream::create('data'); + $this->assertEquals('data', $stream->getContents()); + $stream->close(); + } + public function testGetsContents() { $handle = fopen('php://temp', 'w+');