diff --git a/VERSION.txt b/VERSION.txt index 4ee60801c57..7bfb2d6297b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -16,4 +16,4 @@ // @license https://opensource.org/licenses/mit-license.php MIT License // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -4.6.0 +4.6.1 diff --git a/src/Cache/Engine/MemcachedEngine.php b/src/Cache/Engine/MemcachedEngine.php index 29c56954a4a..687987603bb 100644 --- a/src/Cache/Engine/MemcachedEngine.php +++ b/src/Cache/Engine/MemcachedEngine.php @@ -365,7 +365,7 @@ public function getMultiple($keys, $default = null): array $values = $this->_Memcached->getMulti($cacheKeys); $return = []; foreach ($cacheKeys as $original => $prefixed) { - $return[$original] = $values[$prefixed] ?? $default; + $return[$original] = array_key_exists($prefixed, $values) ? $values[$prefixed] : $default; } return $return; diff --git a/src/Cache/Engine/NullEngine.php b/src/Cache/Engine/NullEngine.php index 4612a276b2f..89defe46792 100644 --- a/src/Cache/Engine/NullEngine.php +++ b/src/Cache/Engine/NullEngine.php @@ -62,7 +62,13 @@ public function get($key, $default = null) */ public function getMultiple($keys, $default = null): iterable { - return []; + $result = []; + + foreach ($keys as $key) { + $result[$key] = $default; + } + + return $result; } /** diff --git a/src/Database/Retry/ReconnectStrategy.php b/src/Database/Retry/ReconnectStrategy.php index ac847810fe6..25fb69f8065 100644 --- a/src/Database/Retry/ReconnectStrategy.php +++ b/src/Database/Retry/ReconnectStrategy.php @@ -109,7 +109,7 @@ protected function reconnect(): bool } try { - $this->connection->connect(); + $this->connection->getDriver()->connect(); if ($this->connection->isQueryLoggingEnabled()) { $this->connection->log('[RECONNECT]'); } diff --git a/src/ORM/BehaviorRegistry.php b/src/ORM/BehaviorRegistry.php index 9f006a1bdfd..fc06b311882 100644 --- a/src/ORM/BehaviorRegistry.php +++ b/src/ORM/BehaviorRegistry.php @@ -203,6 +203,24 @@ protected function _getMethods(Behavior $instance, string $class, string $alias) return compact('methods', 'finders'); } + /** + * Set an object directly into the registry by name. + * + * @param string $name The name of the object to set in the registry. + * @param \Cake\ORM\Behavior $object instance to store in the registry + * @return $this + */ + public function set(string $name, object $object) + { + parent::set($name, $object); + + $methods = $this->_getMethods($object, get_class($object), $name); + $this->_methodMap += $methods['methods']; + $this->_finderMap += $methods['finders']; + + return $this; + } + /** * Remove an object from the registry. * diff --git a/tests/TestCase/Cache/Engine/MemcachedEngineTest.php b/tests/TestCase/Cache/Engine/MemcachedEngineTest.php index f787604c208..c9524ed1d0f 100644 --- a/tests/TestCase/Cache/Engine/MemcachedEngineTest.php +++ b/tests/TestCase/Cache/Engine/MemcachedEngineTest.php @@ -21,6 +21,7 @@ use Cake\Cache\Exception\InvalidArgumentException; use Cake\TestSuite\TestCase; use DateInterval; +use Exception; use Memcached; use function Cake\Core\env; @@ -512,6 +513,36 @@ public function testReadMany(): void $this->assertNull($read['App.doesNotExist']); } + /** + * Test readMany where null is a valid cache value + * + * @throws \Psr\SimpleCache\InvalidArgumentException + */ + public function testReadManyTreatNullAsValidCacheValue(): void + { + $this->_configCache(['duration' => 2]); + $data = [ + 'App.falseTest' => false, + 'App.trueTest' => true, + 'App.nullTest' => null, + 'App.zeroTest' => 0, + 'App.zeroTest2' => '0', + ]; + foreach ($data as $key => $value) { + Cache::write($key, $value, 'memcached'); + } + + $default = new Exception('Cache key not found'); + $read = Cache::pool('memcached')->getMultiple(array_merge(array_keys($data), ['App.doesNotExist']), $default); + + $this->assertFalse($read['App.falseTest']); + $this->assertTrue($read['App.trueTest']); + $this->assertNull($read['App.nullTest']); + $this->assertSame($read['App.zeroTest'], 0); + $this->assertSame($read['App.zeroTest2'], '0'); + $this->assertSame($default, $read['App.doesNotExist']); + } + /** * testWriteMany method */ diff --git a/tests/TestCase/Cache/Engine/NullEngineTest.php b/tests/TestCase/Cache/Engine/NullEngineTest.php new file mode 100644 index 00000000000..3bc67c58771 --- /dev/null +++ b/tests/TestCase/Cache/Engine/NullEngineTest.php @@ -0,0 +1,69 @@ + NullEngine::class, + ]); + } + + public function testReadMany(): void + { + $keys = [ + 'key1', + 'key2', + 'key3', + ]; + + $result1 = Cache::readMany($keys, 'null'); + + $this->assertSame([ + 'key1' => null, + 'key2' => null, + 'key3' => null, + ], $result1); + + $e = new Exception('Cache key not found'); + $result2 = Cache::pool('null')->getMultiple($keys, $e); + + $this->assertSame([ + 'key1' => $e, + 'key2' => $e, + 'key3' => $e, + ], $result2); + } +} diff --git a/tests/TestCase/ORM/BehaviorRegistryTest.php b/tests/TestCase/ORM/BehaviorRegistryTest.php index 7062a3eb660..c09bf5be1d0 100644 --- a/tests/TestCase/ORM/BehaviorRegistryTest.php +++ b/tests/TestCase/ORM/BehaviorRegistryTest.php @@ -24,6 +24,7 @@ use Cake\TestSuite\TestCase; use LogicException; use RuntimeException; +use TestApp\Model\Behavior\SluggableBehavior; /** * Test case for BehaviorRegistry. @@ -209,6 +210,17 @@ public function testLoadDuplicateFinderAliasing(): void $this->assertTrue($this->Behaviors->hasFinder('renamed')); } + /** + * Test set() + */ + public function testSet(): void + { + $this->Behaviors->set('Sluggable', new SluggableBehavior($this->Table, ['replacement' => '_'])); + + $this->assertEquals(['replacement' => '_'], $this->Behaviors->get('Sluggable')->getConfig()); + $this->assertTrue($this->Behaviors->hasMethod('slugify')); + } + /** * test hasMethod() */