Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/35'
Browse files Browse the repository at this point in the history
Close #35
  • Loading branch information
Xerkus committed Feb 14, 2018
2 parents 694b33b + 402d33d commit 2a64bfe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#35](https://github.com/zendframework/zend-psr7bridge/pull/35) fixes the
Response from a PSR-7 Stream object with php://memory stream

## 1.0.1 - 2017-12-18

Expand Down
3 changes: 2 additions & 1 deletion src/Psr7Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
final class Psr7Response
{
const URI_TEMP = 'php://temp';
const URI_MEMORY = 'php://memory';

/**
* Convert a PSR-7 response in a Zend\Http\Response
Expand All @@ -31,7 +32,7 @@ public static function toZend(ResponseInterface $psr7Response)
{
$uri = $psr7Response->getBody()->getMetadata('uri');

if ($uri === static::URI_TEMP) {
if ($uri === static::URI_TEMP || $uri === static::URI_MEMORY) {
$response = sprintf(
"HTTP/%s %d %s\r\n%s\r\n%s",
$psr7Response->getProtocolVersion(),
Expand Down
24 changes: 24 additions & 0 deletions test/Psr7ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ public function testResponseToZend($body, $status, $headers)
}
}

/**
* @dataProvider getResponseData
*/
public function testResponseToZendWithMemoryStream($body, $status, $headers)
{
$stream = new Stream('php://memory', 'wb+');
$stream->write($body);

$psr7Response = new Response($stream, $status, $headers);
$this->assertInstanceOf(ResponseInterface::class, $psr7Response);

$zendResponse = Psr7Response::toZend($psr7Response);
$this->assertInstanceOf(ZendResponse::class, $zendResponse);
$this->assertEquals($body, (string)$zendResponse->getBody());
$this->assertEquals($status, $zendResponse->getStatusCode());

$zendHeaders = $zendResponse->getHeaders()->toArray();
foreach ($headers as $type => $values) {
foreach ($values as $value) {
$this->assertContains($value, $zendHeaders[$type]);
}
}
}

/**
* @dataProvider getResponseData
*/
Expand Down

0 comments on commit 2a64bfe

Please sign in to comment.