diff --git a/CHANGELOG.md b/CHANGELOG.md index 8051d568e..eee9ec7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +2.0.1 +----- + +* Fixed cache key sanitize for PSR-16 cache. +* Fixed not found detection for PSR-16 cache. + 2.0.0 ----- @@ -24,6 +30,12 @@ Changelog 1.x === +1.13.0 +------ + +* Fixed cache key sanitize for PSR-16 cache. +* Fixed not found detection for PSR-16 cache. + 1.12.0 ------ diff --git a/composer.json b/composer.json index 6ed078087..a630e7f09 100644 --- a/composer.json +++ b/composer.json @@ -43,8 +43,10 @@ "psr-0": { "Jackalope\\": "src/" } }, "autoload-dev": { + "psr-4": { + "Jackalope\\Tests\\": "tests/" + }, "psr-0": { - "Jackalope\\Test\\": "tests/", "Jackalope\\": "vendor/jackalope/jackalope/tests", "PHPCR": "vendor/phpcr/phpcr/tests" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ffb7778fa..ab39368b3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,8 +27,8 @@ - tests/Jackalope/Transport - tests/Jackalope/Tools + tests/Transport + tests/Tools vendor/jackalope/jackalope/tests vendor/phpcr/phpcr/tests vendor/phpcr/phpcr-utils/tests diff --git a/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php b/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php index f168554c1..5de420ee1 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php +++ b/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php @@ -50,8 +50,12 @@ public function __construct(FactoryInterface $factory, Connection $conn, array $ } } $this->caches = $caches; - $this->keySanitizer = static function (string $cacheKey): string { - return str_replace(' ', '_', $cacheKey); + $this->keySanitizer = static function ($cacheKey) { + return str_replace( + ['%', '.'], + ['_', '|'], + \urlencode($cacheKey) + ); }; } @@ -219,7 +223,7 @@ public function getNode(string $path): \stdClass $cacheKey = "nodes: $path, ".$this->workspaceName; $cacheKey = $this->sanitizeKey($cacheKey); - if (false !== ($result = $this->caches['nodes']->get($cacheKey))) { + if (null !== ($result = $this->caches['nodes']->get($cacheKey))) { if ('ItemNotFoundException' === $result) { throw new ItemNotFoundException("Item '$path' not found in workspace '$this->workspaceName'"); } @@ -354,7 +358,7 @@ public function getNodePathForIdentifier($uuid, $workspace = null): string $cacheKey = "nodes by uuid: $uuid, $this->workspaceName"; $cacheKey = $this->sanitizeKey($cacheKey); - if (false !== ($result = $this->caches['nodes']->get($cacheKey))) { + if (null !== ($result = $this->caches['nodes']->get($cacheKey))) { if ('ItemNotFoundException' === $result) { throw new ItemNotFoundException("no item found with uuid $uuid"); } @@ -407,7 +411,7 @@ public function getReferences($path, $name = null): array $cacheKey = "nodes references: $path, $name, ".$this->workspaceName; $cacheKey = $this->sanitizeKey($cacheKey); - if (false !== ($result = $this->caches['nodes']->get($cacheKey))) { + if (null !== ($result = $this->caches['nodes']->get($cacheKey))) { return $result; } @@ -449,7 +453,7 @@ public function query(Query $query): array $cacheKey = "query: {$query->getStatement()}, {$query->getLimit()}, {$query->getOffset()}, {$query->getLanguage()}, ".$this->workspaceName; $cacheKey = $this->sanitizeKey($cacheKey); - if (false !== ($result = $this->caches['query']->get($cacheKey))) { + if (null !== ($result = $this->caches['query']->get($cacheKey))) { return $result; } diff --git a/tests/Jackalope/Test/FunctionalTestCase.php b/tests/FunctionalTestCase.php similarity index 91% rename from tests/Jackalope/Test/FunctionalTestCase.php rename to tests/FunctionalTestCase.php index eff0aa1c3..d4fd796b5 100644 --- a/tests/Jackalope/Test/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -1,6 +1,6 @@ getConnection(); $this->loadFixtures($conn); $this->transport = $this->getClient($conn); + $this->assertInstanceOf(WorkspaceManagementInterface::class, $this->transport); $this->transport->createWorkspace('default'); $this->repository = new Repository(null, $this->transport); diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index bc66cc8dd..06a72cba0 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -8,9 +8,9 @@ use Jackalope\Repository; use Jackalope\RepositoryFactoryDoctrineDBAL; use Jackalope\Session; -use Jackalope\Test\Tester\Generic; -use Jackalope\Test\Tester\Mysql; -use Jackalope\Test\Tester\Pgsql; +use Jackalope\Tests\Test\Tester\Generic; +use Jackalope\Tests\Test\Tester\Mysql; +use Jackalope\Tests\Test\Tester\Pgsql; use Jackalope\Transport\DoctrineDBAL\Client; use Jackalope\Transport\Logging\Psr3Logger; use PHPCR\RepositoryException; @@ -141,8 +141,8 @@ public function getRepositoryFactoryParameters() public function getSessionWithLastModified() { - /** @var $session Session */ $session = $this->getSession(); + \assert($session instanceof Session); $session->setSessionOption(Session::OPTION_AUTO_LASTMODIFIED, true); return $session; diff --git a/tests/Jackalope/RepositoryFactoryDoctrineDBALTest.php b/tests/RepositoryFactoryDoctrineDBALTest.php similarity index 92% rename from tests/Jackalope/RepositoryFactoryDoctrineDBALTest.php rename to tests/RepositoryFactoryDoctrineDBALTest.php index 36c067185..b840876f5 100644 --- a/tests/Jackalope/RepositoryFactoryDoctrineDBALTest.php +++ b/tests/RepositoryFactoryDoctrineDBALTest.php @@ -1,8 +1,9 @@ $nodeCache, + 'meta' => $metaCache, + ]); + } +} diff --git a/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php b/tests/Transport/DoctrineDBAL/CachedClientTest.php similarity index 65% rename from tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php rename to tests/Transport/DoctrineDBAL/CachedClientTest.php index 1a33c20d9..6860829b6 100644 --- a/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php +++ b/tests/Transport/DoctrineDBAL/CachedClientTest.php @@ -1,10 +1,11 @@ foo = 'bar'; - $this->cache->set('nodes:_/test,_tests', $cache); + $this->cache->set('nodes_3A+_2Ftest_2C+tests', $cache); $this->assertEquals($cache, $this->transport->getNode('/test')); } /** - * The default key sanitizer replaces spaces with underscores. + * The default key sanitizer keeps the cache key compatible with PSR16. */ public function testDefaultKeySanitizer(): void { - /** @var CachedClient $cachedClient */ - $cachedClient = $this->transport; - $cachedClient->getNodeTypes(); + $client = $this->getClient($this->getConnection()); + $reflection = new \ReflectionClass($client); + $keySanitizerProperty = $reflection->getProperty('keySanitizer'); + $keySanitizerProperty->setAccessible(true); + $defaultKeySanitizer = $keySanitizerProperty->getValue($client); + + $result = $defaultKeySanitizer(' :{}().@/"\\'); // not allowed PSR16 keys - $this->assertTrue($this->cache->has('node_types')); - $this->assertTrue($this->cache->has('nodetypes:_a:0:{}')); + $this->assertEquals('+_3A_7B_7D_28_29|_40_2F_22_5C', $result); } public function testCustomKeySanitizer(): void diff --git a/tests/Jackalope/Transport/DoctrineDBAL/ClientTest.php b/tests/Transport/DoctrineDBAL/ClientTest.php similarity index 98% rename from tests/Jackalope/Transport/DoctrineDBAL/ClientTest.php rename to tests/Transport/DoctrineDBAL/ClientTest.php index 998e6d014..798e84925 100644 --- a/tests/Jackalope/Transport/DoctrineDBAL/ClientTest.php +++ b/tests/Transport/DoctrineDBAL/ClientTest.php @@ -1,9 +1,11 @@ addNode('page3'); $this->session->save(); + $this->assertInstanceOf(WritingInterface::class, $this->transport); $this->transport->moveNodeImmediately('/topic2/page2', '/topic1/page1/page2'); $this->transport->moveNodeImmediately('/topic3', '/topic1/page1/page2/topic3'); @@ -323,7 +326,7 @@ public function testPropertyLengthAttribute(): void $values = $xpath->query('sv:value', $propertyElement->item(0)); - /** @var $value \DOMElement */ + /** @var \DOMElement $value */ foreach ($values as $index => $value) { $lengthAttribute = $value->attributes->getNamedItem('length'); if (null === $lengthAttribute) { diff --git a/tests/Jackalope/Transport/DoctrineDBAL/DeleteCascadeTest.php b/tests/Transport/DoctrineDBAL/DeleteCascadeTest.php similarity index 95% rename from tests/Jackalope/Transport/DoctrineDBAL/DeleteCascadeTest.php rename to tests/Transport/DoctrineDBAL/DeleteCascadeTest.php index d9deb886e..f14521f9b 100644 --- a/tests/Jackalope/Transport/DoctrineDBAL/DeleteCascadeTest.php +++ b/tests/Transport/DoctrineDBAL/DeleteCascadeTest.php @@ -1,9 +1,9 @@