Skip to content

Commit

Permalink
[8.x] Add more readable missing method to Session\Store (#36937)
Browse files Browse the repository at this point in the history
* Add missing helper for session

* Update Store.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
schmidfelix and taylorotwell committed Apr 11, 2021
1 parent bf3d5e3 commit ef99cff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit ef99cff

Please sign in to comment.