From 76b4da674f5be449d20d9a82cb00d6b0193e9b23 Mon Sep 17 00:00:00 2001 From: felixschmid Date: Sat, 10 Apr 2021 20:41:13 +0200 Subject: [PATCH 1/2] Add missing helper for session --- src/Illuminate/Session/Store.php | 11 +++++++++++ tests/Session/SessionStoreTest.php | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Illuminate/Session/Store.php b/src/Illuminate/Session/Store.php index ff2a3b966a20..fdbb44bae256 100755 --- a/src/Illuminate/Session/Store.php +++ b/src/Illuminate/Session/Store.php @@ -193,6 +193,17 @@ public function exists($key) }); } + /** + * Checks if a key is missing. + * + * @param string|array $key + * @return bool + */ + public function missing($key) + { + return ! $this->exists($key); + } + /** * Checks if a key is present and not null. * diff --git a/tests/Session/SessionStoreTest.php b/tests/Session/SessionStoreTest.php index 5871cc657a85..188bdce4d89f 100644 --- a/tests/Session/SessionStoreTest.php +++ b/tests/Session/SessionStoreTest.php @@ -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(); From 82abf62b8c2bf91a13457728be85f3975e7c63c7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 11 Apr 2021 11:11:38 -0500 Subject: [PATCH 2/2] Update Store.php --- src/Illuminate/Session/Store.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Session/Store.php b/src/Illuminate/Session/Store.php index fdbb44bae256..151e8b6330b5 100755 --- a/src/Illuminate/Session/Store.php +++ b/src/Illuminate/Session/Store.php @@ -194,9 +194,9 @@ public function exists($key) } /** - * Checks if a key is missing. + * Determine if the given key is missing from the session data. * - * @param string|array $key + * @param string|array $key * @return bool */ public function missing($key)