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

Commit

Permalink
Merge 90218e0 into 95d89f0
Browse files Browse the repository at this point in the history
  • Loading branch information
boesing committed Dec 19, 2018
2 parents 95d89f0 + 90218e0 commit 6e6a7ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/Psr7Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public static function toZend(ResponseInterface $psr7Response)
$response = new ZendResponse\Stream();

// copy the headers
$zendHeaders = new Headers();
foreach ($psr7Response->getHeaders() as $headerName => $headerValues) {
$zendHeaders->addHeader(new GenericHeader($headerName, implode('; ', $headerValues)));
}
$zendHeaders = Headers::fromString(self::psr7HeadersToString($psr7Response));

// set the status
$response->setStatusCode($psr7Response->getStatusCode());
Expand Down
17 changes: 17 additions & 0 deletions test/Psr7ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
namespace ZendTest\Psr7Bridge;

use Error;
use Iterator;
use PHPUnit\Framework\TestCase as TestCase;
use Psr\Http\Message\ResponseInterface;
use function tmpfile;
use Zend\Diactoros\Response;
use Zend\Diactoros\Stream;
use Zend\Http\Header\SetCookie;
use Zend\Http\Response as ZendResponse;
use Zend\Psr7Bridge\Psr7Response;

Expand Down Expand Up @@ -144,4 +147,18 @@ public function testPrivateConstruct()
$this->expectExceptionMessage(sprintf('Call to private %s::__construct', Psr7Response::class));
new Psr7Response();
}

public function testConvertedHeadersAreInstanceOfTheirAppropriateClasses()
{
$psr7Response = (new Response(tmpfile()))->withAddedHeader('Set-Cookie', 'foo=bar;domain=.zendframework.com');
$zendResponse = Psr7Response::toZend($psr7Response);

$cookies = $zendResponse->getHeaders()->get('Set-Cookie');
$this->assertInstanceOf(Iterator::class, $cookies);
$this->assertCount(1, $cookies);
/** @var SetCookie $cookie */
$cookie = $cookies[0];
$this->assertInstanceOf(SetCookie::class, $cookie);
$this->assertSame('.zendframework.com', $cookie->getDomain());
}
}

0 comments on commit 6e6a7ea

Please sign in to comment.