Skip to content

Commit

Permalink
Add tests for cookie removal and update in FileCookieJar (#3182)
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Dec 3, 2023
1 parent 9338d98 commit 4d6ca3b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/Cookie/FileCookieJarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,55 @@ public function testPersistsToFile($testSaveSessionCookie = false)
\unlink($this->file);
}

public function testRemovesCookie()
{
$jar = new FileCookieJar($this->file);
$jar->setCookie(new SetCookie([
'Name' => 'foo',
'Value' => 'bar',
'Domain' => 'foo.com',
'Expires' => \time() + 1000,
]));

self::assertCount(1, $jar);

// Remove the cookie.
$jar->clear('foo.com', '/', 'foo');

// Confirm that the cookie was removed.
self::assertCount(0, $jar);

\unlink($this->file);
}

public function testUpdatesCookie()
{
$jar = new FileCookieJar($this->file);
$jar->setCookie(new SetCookie([
'Name' => 'foo',
'Value' => 'bar',
'Domain' => 'foo.com',
'Expires' => \time() + 1000,
]));

self::assertCount(1, $jar);

// Update the cookie value.
$jar->setCookie(new SetCookie([
'Name' => 'foo',
'Value' => 'new_value',
'Domain' => 'foo.com',
'Expires' => \time() + 1000,
]));

$cookies = $jar->getIterator()->getArrayCopy();

// Confirm that the cookie was updated.
self::assertEquals('new_value', $cookies[0]->getValue());

\unlink($this->file);
}

public function providerPersistsToFileFileParameters()
{
return [
Expand Down

0 comments on commit 4d6ca3b

Please sign in to comment.