From 026067b485ab3732f2132b0b7a27981a96964ced Mon Sep 17 00:00:00 2001 From: EriBloo <19932449+EriBloo@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:05:27 +0000 Subject: [PATCH] add delete to actions --- src/Concerns/CacheObjectActions.php | 9 +++++++++ tests/CacheObjectTest.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Concerns/CacheObjectActions.php b/src/Concerns/CacheObjectActions.php index 98b69a5..4d93976 100644 --- a/src/Concerns/CacheObjectActions.php +++ b/src/Concerns/CacheObjectActions.php @@ -34,4 +34,13 @@ public function retrieve(): mixed return $driver->get($this); } + + public function delete(): bool + { + /** @var CacheObjectDriver $driver */ + $driver = app() + ->make(CacheObjectDriver::class); + + return $driver->delete($this); + } } diff --git a/tests/CacheObjectTest.php b/tests/CacheObjectTest.php index 1d1b9e1..0e46743 100644 --- a/tests/CacheObjectTest.php +++ b/tests/CacheObjectTest.php @@ -6,6 +6,8 @@ use EriBloo\CacheObjects\Tests\Fixtures\HashedCacheObject; use function PHPUnit\Framework\assertEquals; +use function PHPUnit\Framework\assertNotNull; +use function PHPUnit\Framework\assertNull; it('stores basic cache object', function () { // prepare @@ -29,3 +31,16 @@ assertEquals(hash('sha256', 'hashed-cache-object'), $key); assertEquals('test', $obj->retrieve()); }); + +it('deletes objects properly', function () { + // prepare + $obj = new BasicCacheObject('key'); + $obj->store('test'); + assertNotNull($obj->retrieve()); + + // execute + $obj->delete(); + + // assert + assertNull($obj->retrieve()); +});