From 87d1af45796adc763ce6e28e9e8bc80160a27ddf Mon Sep 17 00:00:00 2001 From: n0nag0n Date: Fri, 7 Mar 2025 17:00:33 -0700 Subject: [PATCH] forgot the getAll() method --- src/Session.php | 10 ++++++++++ tests/SessionTest.php | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Session.php b/src/Session.php index ee63ef8..a88fb8e 100644 --- a/src/Session.php +++ b/src/Session.php @@ -311,6 +311,16 @@ public function clear(): self return $this; } + /** + * Retrieve all session data. + * + * @return array An associative array containing all session data. + */ + public function getAll(): array + { + return $this->data; + } + /** * Commits the current session data and writes it to the storage. * diff --git a/tests/SessionTest.php b/tests/SessionTest.php index 914b4a3..d85bdb9 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -477,4 +477,26 @@ public function testWriteWithNoChanges(): void $result = $writeMethod->invoke($session, $sessionId, 'data'); $this->assertTrue($result); } -} \ No newline at end of file + + public function testGetAll(): void + { + $session = new Session([ + 'save_path' => $this->tempDir, + 'encryption_key' => null, + 'auto_commit' => false, + 'start_session' => false, + 'test_mode' => true + ]); + + $session->set('key1', 'value1'); + $session->set('key2', 'value2'); + + $expectedData = [ + 'key1' => 'value1', + 'key2' => 'value2' + ]; + + $this->assertEquals($expectedData, $session->getAll()); + } + +}