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()); + } + +}