diff --git a/src/Storage/AbstractSessionArrayStorage.php b/src/Storage/AbstractSessionArrayStorage.php index b5ecaf62..7768f1e4 100644 --- a/src/Storage/AbstractSessionArrayStorage.php +++ b/src/Storage/AbstractSessionArrayStorage.php @@ -436,16 +436,9 @@ public function clear($key = null) return $this; } - if (! isset($_SESSION[$key])) { - return $this; - } - - // Clear key data unset($_SESSION[$key]); - - // Clear key metadata $this->setMetadata($key, null) - ->unlock($key); + ->unlock($key); return $this; } diff --git a/test/SessionArrayStorageTest.php b/test/SessionArrayStorageTest.php index 4003b765..c99aae09 100644 --- a/test/SessionArrayStorageTest.php +++ b/test/SessionArrayStorageTest.php @@ -14,6 +14,9 @@ */ class SessionArrayStorageTest extends TestCase { + /** @var SessionArrayStorage */ + private $storage; + protected function setUp(): void { $_SESSION = []; @@ -200,4 +203,20 @@ public function testGetArrayCopyFromContainer(): void $container->baz = 'qux'; self::assertSame(['foo' => 'bar', 'baz' => 'qux'], $container->getArrayCopy()); } + + public function testClearMetaDataIfDontExistInSession(): void + { + $this->storage->setMetadata('foo', 'bar'); + $this->storage->clear('foo'); + + self::assertFalse($this->storage->getMetaData('foo')); + } + + public function testClearRemoveFromSession(): void + { + $this->storage->foo = 'bar'; + $this->storage->clear('foo'); + + self::assertArrayNotHasKey('foo', $_SESSION); + } }