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

[8.x] Add more readable missing method to Session\Store #36937

Merged
merged 2 commits into from Apr 11, 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
11 changes: 11 additions & 0 deletions src/Illuminate/Session/Store.php
Expand Up @@ -193,6 +193,17 @@ public function exists($key)
});
}

/**
* Determine if the given key is missing from the session data.
*
* @param string|array $key
* @return bool
*/
public function missing($key)
{
return ! $this->exists($key);
}

/**
* Checks if a key is present and not null.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Session/SessionStoreTest.php
Expand Up @@ -452,6 +452,22 @@ public function testKeyExists()
$this->assertFalse($session->exists(['hulk.two']));
}

public function testKeyMissing()
{
$session = $this->getSession();
$session->put('foo', 'bar');
$this->assertFalse($session->missing('foo'));
$session->put('baz', null);
$session->put('hulk', ['one' => true]);
$this->assertFalse($session->has('baz'));
$this->assertFalse($session->missing('baz'));
$this->assertTrue($session->missing('bogus'));
$this->assertFalse($session->missing(['foo', 'baz']));
$this->assertTrue($session->missing(['foo', 'baz', 'bogus']));
$this->assertFalse($session->missing(['hulk.one']));
$this->assertTrue($session->missing(['hulk.two']));
}

public function testRememberMethodCallsPutAndReturnsDefault()
{
$session = $this->getSession();
Expand Down