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

Added missing constructor parameter #3287

Merged
merged 3 commits into from
Jan 3, 2013
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
10 changes: 7 additions & 3 deletions library/Zend/Http/Client/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
namespace Zend\Http\Client;

use ArrayIterator;
use Zend\Http\Header\Cookie;
use Zend\Http\Header\SetCookie;
use Zend\Stdlib\ArrayUtils;
use Zend\Http\Response;
use Zend\Uri;

Expand Down Expand Up @@ -93,7 +94,7 @@ public function __construct()
* Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object
* or as a string - in which case an object is created from the string.
*
* @param Cookie|string $cookie
* @param SetCookie|string $cookie
* @param Uri\Uri|string $ref_uri Optional reference URI (for domain, path, secure)
* @throws Exception\InvalidArgumentException if invalid $cookie value
*/
Expand All @@ -103,7 +104,7 @@ public function addCookie($cookie, $ref_uri = null)
$cookie = Cookie::fromString($cookie, $ref_uri);
Copy link
Member

Choose a reason for hiding this comment

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

Do you still intend for this to use Cookie (vs. SetCookie)? If so, you need to re-add the import; if not, this should be updated.

}

if ($cookie instanceof Cookie) {
if ($cookie instanceof SetCookie) {
$domain = $cookie->getDomain();
$path = $cookie->getPath();
if (!isset($this->cookies[$domain])) {
Expand All @@ -128,6 +129,9 @@ public function addCookie($cookie, $ref_uri = null)
public function addCookiesFromResponse(Response $response, $ref_uri)
{
$cookie_hdrs = $response->getHeaders()->get('Set-Cookie');
if ($cookie_hdrs instanceof \ArrayIterator) {
Copy link
Member

Choose a reason for hiding this comment

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

Use Traversable here, not ArrayIterator.

$cookie_hdrs = ArrayUtils::iteratorToArray($cookie_hdrs);
}

if (is_array($cookie_hdrs)) {
foreach ($cookie_hdrs as $cookie) {
Expand Down
6 changes: 2 additions & 4 deletions library/Zend/Http/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ public static function fromString($string)
);
}

public function __construct(Headers $headers)
{
$this->headers = $headers;
}
public function __construct()
{ }
Copy link
Member

Choose a reason for hiding this comment

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

If the constructor won't be doing anything, remove it.


/**
* Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object
Expand Down
47 changes: 47 additions & 0 deletions tests/ZendTest/Http/CookiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Http
*/

namespace ZendTest\Http;

use Zend\Http\Header\SetCookie;
use Zend\Http\Response;
use \Zend\Http\Headers;


class CookiesTest extends \PHPUnit_Framework_TestCase
{
public function testFromResponseInSetCookie()
{
$response = new Response();
$headers = new Headers();
$header = new \Zend\Http\Header\SetCookie("foo", "bar");
$header->setDomain("www.zend.com");
$header->setPath("/");
$headers->addHeader($header);
$response->setHeaders($headers);

$response = \Zend\Http\Cookies::fromResponse($response, "http://www.zend.com");
$this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo'));
}

public function testFromResponseInCookie()
{
$response = new Response();
$headers = new Headers();
$header = new \Zend\Http\Header\SetCookie("foo", "bar");
$header->setDomain("www.zend.com");
$header->setPath("/");
$headers->addHeader($header);
$response->setHeaders($headers);

$response = \Zend\Http\Client\Cookies::fromResponse($response, "http://www.zend.com");
$this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo'));
}
}