From 30aafede5cee3b29b1a65aae07efe92efda51d0b Mon Sep 17 00:00:00 2001 From: Sergey Mutaf Date: Thu, 7 Dec 2023 09:56:33 +0200 Subject: [PATCH] fix: `CacheBridgeAbstract::save()` not assigning value to cache when cache hit mises (#434) * Fixed item cache value Signed-off-by: Sergey Mutaf * Update tests for successful passing --------- Signed-off-by: Sergey Mutaf Co-authored-by: Evan Sims Co-authored-by: Evan Sims --- src/Bridges/CacheBridgeAbstract.php | 2 +- tests/Unit/Bridges/CacheBridgeTest.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Bridges/CacheBridgeAbstract.php b/src/Bridges/CacheBridgeAbstract.php index 8f7e45b3..e4c487db 100644 --- a/src/Bridges/CacheBridgeAbstract.php +++ b/src/Bridges/CacheBridgeAbstract.php @@ -118,7 +118,7 @@ final public function save(CacheItemInterface $item): bool return false; } - $value = serialize($item->get()); + $value = serialize($item->getRawValue()); $key = $item->getKey(); $expires = $item->getExpiration(); diff --git a/tests/Unit/Bridges/CacheBridgeTest.php b/tests/Unit/Bridges/CacheBridgeTest.php index 437de083..58205617 100644 --- a/tests/Unit/Bridges/CacheBridgeTest.php +++ b/tests/Unit/Bridges/CacheBridgeTest.php @@ -36,9 +36,7 @@ expect($cache) ->toBeInstanceOf(CacheItemBridge::class) ->isHit()->toBeTrue() - ->get()->toBeNull() - ->set(42) - ->get()->toBe(42); + ->get()->toEqual(42); $results = $pool->getItems(); @@ -46,12 +44,12 @@ ->toBeArray() ->toHaveCount(0); - $results = $pool->getItems(['testing' => uniqid()]); + $results = $pool->getItems(['testing']); expect($results['testing']) ->toBeInstanceOf(CacheItemBridge::class) ->isHit()->toBeTrue() - ->get()->not()->toBe(42); + ->get()->toEqual(42); $this->app[\Illuminate\Cache\CacheManager::class] ->getStore()