Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating a stream from string has unexpected behaviour #177

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE the discussion in #176, i find it highly unexpected that this does not work.

$stream->close();
}

public function testGetsContents()
{
$handle = fopen('php://temp', 'w+');
Expand Down