Browse Source

change to withExpiredCookie

Joris Vaesen 8 years ago
parent
commit
c5dda9cc2f

+ 1 - 1
src/Http/Cookie/Cookie.php

@@ -510,7 +510,7 @@ class Cookie implements CookieInterface
     public function withExpired()
     {
         $new = clone $this;
-        $new->expiresAt = Chronos::parse('-1 year');
+        $new->expiresAt = Chronos::createFromTimestamp(1);
 
         return $new;
     }

+ 8 - 11
src/Http/Response.php

@@ -2047,8 +2047,6 @@ class Response implements ResponseInterface
      * ### 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 @@ class Response implements ResponseInterface
      *
      * ```
      * // 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 @@ class Response implements ResponseInterface
 
             $cookie = new Cookie(
                 $name,
-                $options['value'],
+                '',
                 new Time(1),
                 $options['path'],
                 $options['domain'],

+ 1 - 2
tests/TestCase/Http/Cookie/CookieTest.php

@@ -298,8 +298,7 @@ class CookieTest extends TestCase
         $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());
     }
 
     /**

+ 7 - 6
tests/TestCase/Http/ResponseTest.php

@@ -1491,19 +1491,19 @@ class ResponseTest extends TestCase
         $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 @@ class ResponseTest extends TestCase
         $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']);