From 91c2d91f46232c9e2175ffda92268a5e4ce01dea Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 21 Nov 2023 18:10:21 +0100 Subject: [PATCH] fix cache BC handling in CachedClient and add test --- CHANGELOG.md | 5 +++++ .../Transport/DoctrineDBAL/CachedClient.php | 7 +++---- .../Transport/DoctrineDBAL/CachedClientTest.php | 16 +++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfc14b2b..66ee69ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Changelog 1.x === +1.10.1 +------ + +* Bugfix: Correctly handle cache fetches in CachedClient BC layer. + 1.10.0 ------ diff --git a/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php b/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php index 853d9fde..7af32c7f 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php +++ b/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php @@ -664,10 +664,9 @@ private function set(string $name, string $key, $value): void private function get(string $name, string $key) { if ($this->caches[$name] instanceof CacheInterface) { - $this->caches[$name]->get($key); - - return; + return $this->caches[$name]->get($key); } - $this->caches[$name]->fetch($key); + + return $this->caches[$name]->fetch($key); } } diff --git a/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php b/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php index cb023efa..55326f5e 100644 --- a/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php +++ b/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php @@ -2,7 +2,7 @@ namespace Jackalope\Transport\DoctrineDBAL; -use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Cache; use Doctrine\DBAL\Connection; use Jackalope\Factory; use Jackalope\Test\FunctionalTestCase; @@ -11,13 +11,13 @@ class CachedClientTest extends FunctionalTestCase { /** - * @var ArrayCache|MockObject + * @var Cache|MockObject */ private $cacheMock; protected function getClient(Connection $conn) { - $this->cacheMock = $this->createMock(ArrayCache::class); + $this->cacheMock = $this->createMock(Cache::class); return new CachedClient(new Factory(), $conn, ['nodes' => $this->cacheMock, 'meta' => $this->cacheMock]); } @@ -28,6 +28,14 @@ public function testArrayObjectIsConvertedToArray() self::assertIsArray($namespaces); } + public function testCacheHit() + { + $cache = new \stdClass(); + $this->cacheMock->method('fetch')->with('nodes:_/test,_tests')->willReturn($cache); + + $this->assertSame($cache, $this->transport->getNode('/test')); + } + /** * The default key sanitizer replaces spaces with underscores */ @@ -67,8 +75,6 @@ public function testCustomkeySanitizer() return true; })); - /** @var CachedClient $cachedClient */ - $cachedClient = $this->transport; $cachedClient->getNodeTypes(); } }