From b3c4c53e63fd32bdaa1292e5d9a68013ab06eec6 Mon Sep 17 00:00:00 2001 From: Joel Male Date: Wed, 27 May 2026 20:47:14 +1000 Subject: [PATCH] feat: add NullDriver --- src/Drivers/NullDriver.php | 67 +++++++++++++++++++++++++++ tests/Unit/Drivers/NullDriverTest.php | 62 +++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 src/Drivers/NullDriver.php create mode 100644 tests/Unit/Drivers/NullDriverTest.php diff --git a/src/Drivers/NullDriver.php b/src/Drivers/NullDriver.php new file mode 100644 index 0000000..91187d2 --- /dev/null +++ b/src/Drivers/NullDriver.php @@ -0,0 +1,67 @@ +sessionKey; + } + + public function setSessionKey(string $sessionKey): void + { + $this->sessionKey = $sessionKey; + } + + public function getDriverName(): string + { + return 'null'; + } + + public function getItems(): array + { + return $this->items; + } + + public function putItems(array $items): void + { + $this->items = $items; + } + + public function getConditions(): array + { + return $this->conditions; + } + + public function putConditions(array $conditions): void + { + $this->conditions = $conditions; + } + + public function clearItems(): void + { + $this->items = []; + } + + public function flush(): void + { + $this->items = []; + $this->conditions = []; + } + + public function getSessionModel(): mixed + { + return null; + } +} diff --git a/tests/Unit/Drivers/NullDriverTest.php b/tests/Unit/Drivers/NullDriverTest.php new file mode 100644 index 0000000..34c5b84 --- /dev/null +++ b/tests/Unit/Drivers/NullDriverTest.php @@ -0,0 +1,62 @@ +driver = new NullDriver('test-session'); + }); + + test('returns its session key', function () { + expect($this->driver->getSessionKey())->toBe('test-session'); + }); + + test('returns null as driver name', function () { + expect($this->driver->getDriverName())->toBe('null'); + }); + + test('starts with empty items', function () { + expect($this->driver->getItems())->toBe([]); + }); + + test('stores and retrieves items', function () { + $this->driver->putItems([['id' => 1, 'name' => 'Widget']]); + expect($this->driver->getItems())->toBe([['id' => 1, 'name' => 'Widget']]); + }); + + test('starts with empty conditions', function () { + expect($this->driver->getConditions())->toBe([]); + }); + + test('stores and retrieves conditions', function () { + $this->driver->putConditions([['name' => 'GST', 'type' => 'tax', 'value' => '10%']]); + expect($this->driver->getConditions())->toBe([['name' => 'GST', 'type' => 'tax', 'value' => '10%']]); + }); + + test('clearItems empties items but keeps conditions', function () { + $this->driver->putItems([['id' => 1]]); + $this->driver->putConditions([['name' => 'GST']]); + $this->driver->clearItems(); + + expect($this->driver->getItems())->toBe([]); + expect($this->driver->getConditions())->toBe([['name' => 'GST']]); + }); + + test('flush empties items and conditions', function () { + $this->driver->putItems([['id' => 1]]); + $this->driver->putConditions([['name' => 'GST']]); + $this->driver->flush(); + + expect($this->driver->getItems())->toBe([]); + expect($this->driver->getConditions())->toBe([]); + }); + + test('setSessionKey updates the key', function () { + $this->driver->setSessionKey('new-key'); + expect($this->driver->getSessionKey())->toBe('new-key'); + }); + + test('getSessionModel returns null', function () { + expect($this->driver->getSessionModel())->toBeNull(); + }); +});