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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch cookies get() method in case a value is null #150

Merged
merged 2 commits into from
Jan 28, 2020
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
3 changes: 2 additions & 1 deletion src/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use InvalidArgumentException;

use function array_key_exists;
use function array_replace;
use function count;
use function explode;
Expand Down Expand Up @@ -89,7 +90,7 @@ public function setDefaults(array $settings): self
*/
public function get(string $name, $default = null)
{
return isset($this->requestCookies[$name]) ? $this->requestCookies[$name] : $default;
return array_key_exists($name, $this->requestCookies) ? $this->requestCookies[$name] : $default;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/CookiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ public function testSetSameSiteCookieValuesAreCaseInsensitive()

public function testGet()
{
$cookies = new Cookies(['foo' => 'bar']);
$cookies = new Cookies(['foo' => 'bar', 'baz' => null]);
$this->assertEquals('bar', $cookies->get('foo'));
$this->assertNull($cookies->get('baz', 'defaultValue'));
$this->assertNull($cookies->get('missing'));
$this->assertEquals('defaultValue', $cookies->get('missing', 'defaultValue'));
}
Expand Down