Skip to content
Permalink
Browse files

Add getCookies() method to response.

this method better follows the segregated getter method style we've been
adopting.
  • Loading branch information...
markstory committed Jan 1, 2017
1 parent 4efbfcd commit d6a720b2c0d21afffb644933aa7a406eccd63772
Showing with 53 additions and 1 deletion.
  1. +13 −1 src/Http/Response.php
  2. +40 −0 tests/TestCase/Network/ResponseTest.php
@@ -1925,7 +1925,7 @@ public function __toString()
* @param array|null $options Either null to get all cookies, string for a specific cookie
* or array to set cookie.
* @return mixed
* @deprecated 3.4.0 Use getCookie() and withCookie() instead.
* @deprecated 3.4.0 Use getCookie(), getCookies() and withCookie() instead.
*/
public function cookie($options = null)
{
@@ -2022,6 +2022,18 @@ public function getCookie($name)
return null;
}
/**
* Get all cookies in the response.
*
* Returns an associative array of cookie name => cookie data.
*
* @return array
*/
public function getCookies()
{
return $this->_cookies;
}
/**
* Setup access for origin and methods on cross origin requests
*
@@ -1429,6 +1429,46 @@ public function testWithCookieArray()
$this->assertEquals($expected, $new->getCookie('testing'));
}
/**
* Test getCookies() and array data.
*
* @return void
*/
public function testGetCookies()
{
$response = new Response();
$cookie = [
'name' => 'ignored key',
'value' => '[a,b,c]',
'expire' => 1000,
'path' => '/test',
'secure' => true
];
$new = $response->withCookie('testing', 'a')
->withCookie('test2', ['value' => 'b', 'path' => '/test', 'secure' => true]);
$expected = [
'testing' => [
'name' => 'testing',
'value' => 'a',
'expire' => null,
'path' => '/',
'domain' => '',
'secure' => false,
'httpOnly' => false
],
'test2' => [
'name' => 'test2',
'value' => 'b',
'expire' => null,
'path' => '/test',
'domain' => '',
'secure' => true,
'httpOnly' => false
]
];
$this->assertEquals($expected, $new->getCookies());
}
/**
* Test CORS
*

0 comments on commit d6a720b

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