Skip to content

Commit

Permalink
fix cache BC handling in CachedClient and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Nov 21, 2023
1 parent e8a7d02 commit 91c2d91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
1.x
===

1.10.1
------

* Bugfix: Correctly handle cache fetches in CachedClient BC layer.

1.10.0
------

Expand Down
7 changes: 3 additions & 4 deletions src/Jackalope/Transport/DoctrineDBAL/CachedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 11 additions & 5 deletions tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
}
Expand All @@ -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
*/
Expand Down Expand Up @@ -67,8 +75,6 @@ public function testCustomkeySanitizer()
return true;
}));

/** @var CachedClient $cachedClient */
$cachedClient = $this->transport;
$cachedClient->getNodeTypes();
}
}

0 comments on commit 91c2d91

Please sign in to comment.