Skip to content

Update dependencies and cookie plugin #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2015
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
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
"psr/log": "^1.0",
"psr/cache": "^1.0",
"php-http/client-common": "^0.1.1",
"php-http/message": "^0.1.1",
"php-http/message": "^0.2",
"symfony/options-resolver": "^2.6|^3.0"
},
"require-dev": {
"php-http/cookie": "^0.1@dev",
"symfony/stopwatch": "^2.3",
"phpspec/phpspec": "^2.4",
"henrikbjorn/phpspec-code-coverage" : "^1.0"
Expand All @@ -38,7 +37,6 @@
}
},
"suggest": {
"php-http/cookie": "Allow to use CookiePlugin",
"symfony/stopwatch": "Allow to use the StopwatchPlugin",
"psr/log-implementation": "Allow to use the LoggerPlugin",
"psr/cache-implementation": "Allow to use the CachePlugin"
Expand Down
55 changes: 27 additions & 28 deletions spec/CookiePluginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace spec\Http\Client\Plugin;

use Http\Promise\FulfilledPromise;
use Http\Cookie\Cookie;
use Http\Cookie\CookieJar;
use Http\Message\Cookie;
use Http\Message\CookieJar;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -14,9 +14,13 @@

class CookiePluginSpec extends ObjectBehavior
{
function let(CookieJar $cookieJar)
private $cookieJar;

function let()
{
$this->beConstructedWith($cookieJar);
$this->cookieJar = new CookieJar();

$this->beConstructedWith($this->cookieJar);
}

function it_is_initializable()
Expand All @@ -29,11 +33,11 @@ function it_is_a_plugin()
$this->shouldImplement('Http\Client\Plugin\Plugin');
}

function it_loads_cookie(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
function it_loads_cookie(RequestInterface $request, UriInterface $uri, Promise $promise)
{
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com');
$cookie = new Cookie('name', 'value', 86400, 'test.com');
$this->cookieJar->addCookie($cookie);

$cookieJar->getCookies()->willReturn([$cookie]);
$request->getUri()->willReturn($uri);
$uri->getHost()->willReturn('test.com');
$uri->getPath()->willReturn('/');
Expand All @@ -47,11 +51,11 @@ function it_loads_cookie(CookieJar $cookieJar, RequestInterface $request, UriInt
}, function () {});
}

function it_does_not_load_cookie_if_expired(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
function it_does_not_load_cookie_if_expired(RequestInterface $request, UriInterface $uri, Promise $promise)
{
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('-1day'), 'test.com');
$cookie = new Cookie('name', 'value', null, 'test.com', false, false, null, (new \DateTime())->modify('-1 day'));
$this->cookieJar->addCookie($cookie);

$cookieJar->getCookies()->willReturn([$cookie]);
$request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled();

$this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) {
Expand All @@ -61,11 +65,11 @@ function it_does_not_load_cookie_if_expired(CookieJar $cookieJar, RequestInterfa
}, function () {});
}

function it_does_not_load_cookie_if_domain_does_not_match(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
function it_does_not_load_cookie_if_domain_does_not_match(RequestInterface $request, UriInterface $uri, Promise $promise)
{
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test2.com');
$cookie = new Cookie('name', 'value', 86400, 'test2.com');
$this->cookieJar->addCookie($cookie);

$cookieJar->getCookies()->willReturn([$cookie]);
$request->getUri()->willReturn($uri);
$uri->getHost()->willReturn('test.com');

Expand All @@ -78,11 +82,11 @@ function it_does_not_load_cookie_if_domain_does_not_match(CookieJar $cookieJar,
}, function () {});
}

function it_does_not_load_cookie_if_path_does_not_match(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
function it_does_not_load_cookie_if_path_does_not_match(RequestInterface $request, UriInterface $uri, Promise $promise)
{
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com', '/sub');
$cookie = new Cookie('name', 'value', 86400, 'test.com', '/sub');
$this->cookieJar->addCookie($cookie);

$cookieJar->getCookies()->willReturn([$cookie]);
$request->getUri()->willReturn($uri);
$uri->getHost()->willReturn('test.com');
$uri->getPath()->willReturn('/');
Expand All @@ -96,11 +100,11 @@ function it_does_not_load_cookie_if_path_does_not_match(CookieJar $cookieJar, Re
}, function () {});
}

function it_does_not_load_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
function it_does_not_load_cookie_when_cookie_is_secure(RequestInterface $request, UriInterface $uri, Promise $promise)
{
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com', null, true);
$cookie = new Cookie('name', 'value', 86400, 'test.com', null, true);
$this->cookieJar->addCookie($cookie);

$cookieJar->getCookies()->willReturn([$cookie]);
$request->getUri()->willReturn($uri);
$uri->getHost()->willReturn('test.com');
$uri->getPath()->willReturn('/');
Expand All @@ -115,11 +119,11 @@ function it_does_not_load_cookie_when_cookie_is_secure(CookieJar $cookieJar, Req
}, function () {});
}

function it_loads_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
function it_loads_cookie_when_cookie_is_secure(RequestInterface $request, UriInterface $uri, Promise $promise)
{
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com', null, true);
$cookie = new Cookie('name', 'value', 86400, 'test.com', null, true);
$this->cookieJar->addCookie($cookie);

$cookieJar->getCookies()->willReturn([$cookie]);
$request->getUri()->willReturn($uri);
$uri->getHost()->willReturn('test.com');
$uri->getPath()->willReturn('/');
Expand All @@ -134,10 +138,8 @@ function it_loads_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInte
}, function () {});
}

function it_saves_cookie(CookieJar $cookieJar, RequestInterface $request, ResponseInterface $response, UriInterface $uri)
function it_saves_cookie(RequestInterface $request, ResponseInterface $response, UriInterface $uri)
{
$cookieJar->getCookies()->willReturn([]);

$next = function () use ($response) {
return new FulfilledPromise($response->getWrappedObject());
};
Expand All @@ -147,9 +149,6 @@ function it_saves_cookie(CookieJar $cookieJar, RequestInterface $request, Respon
'cookie=value',
]);

$cookie = new Cookie('cookie', 'value', 0, 'test.com');
$cookieJar->addCookie($cookie)->shouldBeCalled();

$request->getUri()->willReturn($uri);
$uri->getHost()->willReturn('test.com');
$uri->getPath()->willReturn('/');
Expand Down
4 changes: 2 additions & 2 deletions src/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Http\Client\Plugin;

use Http\Cookie\Cookie;
use Http\Cookie\CookieJar;
use Http\Message\Cookie;
use Http\Message\CookieJar;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand Down