Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add Cookie::queueForget() method #37072

Merged
merged 3 commits into from Apr 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Illuminate/Cookie/CookieJar.php
Expand Up @@ -153,6 +153,19 @@ public function queue(...$parameters)
$this->queued[$cookie->getName()][$cookie->getPath()] = $cookie;
}

/**
* Queue a cookie to expire with the next response.
*
* @param string $name
* @param string|null $path
* @param string|null $domain
* @return void
*/
public function queueForget($name, $path = null, $domain = null)
{
$this->queue($this->forget($name, $path, $domain));
}

/**
* Remove a cookie from the queue.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Cookie/CookieTest.php
Expand Up @@ -118,6 +118,22 @@ public function testHasQueuedWithPath(): void
$this->assertFalse($cookieJar->hasQueued('foo', '/wrongPath'));
}

public function testQueueForget()
{
$cookieJar = $this->getCreator();
$this->assertCount(0, $cookieJar->getQueuedCookies());

$cookieJar->queueForget('foobar', '/path', '/domain');

$cookie = $cookieJar->queued('foobar');
$this->assertEquals('foobar', $cookie->getName());
$this->assertEquals(null, $cookie->getValue());
$this->assertEquals('/path', $cookie->getPath());
$this->assertEquals('/domain', $cookie->getDomain());
$this->assertTrue($cookie->getExpiresTime() < time());
$this->assertCount(1, $cookieJar->getQueuedCookies());
}

public function testUnqueue()
{
$cookie = $this->getCreator();
Expand Down