Skip to content

Commit

Permalink
rewind in-memory stream to have expected behaviour (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed May 10, 2021
1 parent 902515f commit d937173
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+');
Expand Down

0 comments on commit d937173

Please sign in to comment.