Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cache BC handling in CachedClient and add test #430

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading