Skip to content
Permalink
Browse files

Use getCookies() and add test for emitting cookies

  • Loading branch information...
markstory committed Jan 1, 2017
1 parent ea7c52b commit 30fc50028d7da38ea88e0a6a4b50e6d97ad803d4
Showing with 49 additions and 3 deletions.
  1. +2 −2 src/Http/ResponseEmitter.php
  2. +47 −1 tests/TestCase/Http/ResponseEmitterTest.php
@@ -163,8 +163,8 @@ protected function emitStatusLine(ResponseInterface $response)
protected function emitHeaders(ResponseInterface $response)
{
$cookies = [];
if (method_exists($response, 'cookie')) {
$cookies = $response->cookie();
if (method_exists($response, 'getCookies')) {
$cookies = $response->getCookies();
}
foreach ($response->getHeaders() as $name => $values) {
@@ -15,9 +15,9 @@
namespace Cake\Test\TestCase;
use Cake\Http\CallbackStream;
use Cake\Http\Response;
use Cake\Http\ResponseEmitter;
use Cake\TestSuite\TestCase;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Stream;
@@ -87,6 +87,52 @@ public function testEmitNoContentResponse()
$this->assertEquals($expected, $GLOBALS['mockedHeaders']);
}
/**
* Test emitting responses with array cookes
*
* @return void
*/
public function testEmitResponseArrayCookies()
{
$response = (new Response())
->withCookie('simple', ['value' => 'val', 'secure' => true])
->withAddedHeader('Set-Cookie', 'google=not=nice;Path=/accounts; HttpOnly')
->withHeader('Content-Type', 'text/plain');
$response->getBody()->write('ok');
ob_start();
$this->emitter->emit($response);
$out = ob_get_clean();
$this->assertEquals('ok', $out);
$expected = [
'HTTP/1.1 200 OK',
'Content-Type: text/plain'
];
$this->assertEquals($expected, $GLOBALS['mockedHeaders']);
$expected = [
[
'name' => 'simple',
'value' => 'val',
'path' => '/',
'expire' => 0,
'domain' => '',
'secure' => true,
'httponly' => false
],
[
'name' => 'google',
'value' => 'not=nice',
'path' => '/accounts',
'expire' => 0,
'domain' => '',
'secure' => false,
'httponly' => true
],
];
$this->assertEquals($expected, $GLOBALS['mockedCookies']);
}
/**
* Test emitting responses with cookies
*

0 comments on commit 30fc500

Please sign in to comment.
You can’t perform that action at this time.