Skip to content
Permalink
Browse files

change to withExpiredCookie

  • Loading branch information...
Joris Vaesen
Joris Vaesen committed Aug 3, 2017
1 parent 862c12f commit c5dda9cc2f1188cfeb7d13870db61bb3322b72d4
@@ -510,7 +510,7 @@ public function withNeverExpire()
public function withExpired()
{
$new = clone $this;
$new->expiresAt = Chronos::parse('-1 year');
$new->expiresAt = Chronos::createFromTimestamp(1);
return $new;
}
@@ -2047,8 +2047,6 @@ public function withCookie($name, $data = '')
* ### Options
*
* - `name`: The Cookie name
* - `value`: Value of the cookie
* - `expire`: Time the cookie expires in
* - `path`: Path the cookie applies to
* - `domain`: Domain the cookie is for.
* - `secure`: Is the cookie https?
@@ -2058,26 +2056,25 @@ public function withCookie($name, $data = '')
*
* ```
* // set scalar value with defaults
* $response = $response->withoutCookie('remember_me');
* $response = $response->withExpiredCookie('remember_me');
*
* // customize cookie attributes
* $response = $response->withoutCookie('remember_me', ['path' => '/login']);
* $response = $response->withExpiredCookie('remember_me', ['path' => '/login']);
*
* // add a cookie object
* $response = $response->withoutCookie(new Cookie('remember_me', 'deleted'));
* $response = $response->withExpiredCookie(new Cookie('remember_me'));
* ```
*
* @param string|\Cake\Http\Cookie\Cookie $name The name of the cookie to expire, or a cookie object
* @param string|\Cake\Http\Cookie\CookieInterface $name The name of the cookie to expire, or a cookie object
* @param array $options An array of cookie options.
* @return static
*/
public function withoutCookie($name, $options = [])
public function withExpiredCookie($name, $options = [])
{
if ($name instanceof Cookie) {
$cookie = $name->withExpiry(new Time(1));
if ($name instanceof CookieInterface) {
$cookie = $name->withExpired();
} else {
$options += [
'value' => '',
'path' => '/',
'domain' => '',
'secure' => false,
@@ -2086,7 +2083,7 @@ public function withoutCookie($name, $options = [])
$cookie = new Cookie(
$name,
$options['value'],
'',
new Time(1),
$options['path'],
$options['domain'],
@@ -298,8 +298,7 @@ public function testWithExpired()
$this->assertNotSame($new, $cookie, 'Should clone');
$this->assertNotContains('expiry', $cookie->toHeaderValue());
$now = Chronos::parse('-1 year');
$this->assertContains($now->format('Y'), $new->toHeaderValue());
$this->assertContains('01-Jan-1970', $new->toHeaderValue());
}
/**
@@ -1491,19 +1491,19 @@ public function testWithCookieObject()
$this->assertSame($cookie, $new->getCookieCollection()->get('yay'));
}
public function testWithoutCookieScalar()
public function testWithExpiredCookieScalar()
{
$response = new Response();
$response = $response->withCookie('testing', 'abc123');
$this->assertEquals('abc123', $response->getCookie('testing')['value']);
$new = $response->withoutCookie('testing');
$new = $response->withExpiredCookie('testing');
$this->assertNull($response->getCookie('testing')['expire']);
$this->assertEquals('1', $new->getCookie('testing')['expire']);
}
public function testWithoutCookieOptions()
public function testWithExpiredCookieOptions()
{
$options = [
'name' => 'testing',
@@ -1519,20 +1519,21 @@ public function testWithoutCookieOptions()
$response = $response->withCookie('testing', $options);
$this->assertEquals($options, $response->getCookie('testing'));
$new = $response->withoutCookie('testing', $options);
$new = $response->withExpiredCookie('testing', $options);
$this->assertEquals($options['expire'], $response->getCookie('testing')['expire']);
$this->assertEquals('1', $new->getCookie('testing')['expire']);
$this->assertEquals('', $new->getCookie('testing')['value']);
}
public function testWithoutCookieObject()
public function testWithExpiredCookieObject()
{
$response = new Response();
$cookie = new Cookie('yay', 'a value');
$response = $response->withCookie($cookie);
$this->assertEquals('a value', $response->getCookie('yay')['value']);
$new = $response->withoutCookie($cookie);
$new = $response->withExpiredCookie($cookie);
$this->assertNull($response->getCookie('yay')['expire']);
$this->assertEquals('1', $new->getCookie('yay')['expire']);

0 comments on commit c5dda9c

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