From 4af08d82b29cf1e61ae109942c4d91a2b0d07bc8 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 14 Jul 2019 23:23:20 +0200 Subject: [PATCH] Added string type-hint for get() and a test case for it --- src/Core/Config/Cache/ConfigCache.php | 2 +- src/Core/Config/Cache/PConfigCache.php | 2 +- tests/src/Core/Config/Cache/ConfigCacheTest.php | 6 ++++++ tests/src/Core/Config/Cache/PConfigCacheTest.php | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Core/Config/Cache/ConfigCache.php b/src/Core/Config/Cache/ConfigCache.php index bafb3fc957..3119b5db12 100644 --- a/src/Core/Config/Cache/ConfigCache.php +++ b/src/Core/Config/Cache/ConfigCache.php @@ -68,7 +68,7 @@ class ConfigCache * * @return null|mixed Returns the value of the Config entry or null if not set */ - public function get(string $cat, $key = null) + public function get(string $cat, string $key = null) { if (isset($this->config[$cat][$key])) { return $this->config[$cat][$key]; diff --git a/src/Core/Config/Cache/PConfigCache.php b/src/Core/Config/Cache/PConfigCache.php index 4ee2bfae72..b03d86f41e 100644 --- a/src/Core/Config/Cache/PConfigCache.php +++ b/src/Core/Config/Cache/PConfigCache.php @@ -62,7 +62,7 @@ class PConfigCache * * @return null|string The value of the config entry or null if not set */ - public function get(int $uid, string $cat, $key = null) + public function get(int $uid, string $cat, string $key = null) { if (isset($this->config[$uid][$cat][$key])) { return $this->config[$uid][$cat][$key]; diff --git a/tests/src/Core/Config/Cache/ConfigCacheTest.php b/tests/src/Core/Config/Cache/ConfigCacheTest.php index db92cc7436..d8ac3eaea4 100644 --- a/tests/src/Core/Config/Cache/ConfigCacheTest.php +++ b/tests/src/Core/Config/Cache/ConfigCacheTest.php @@ -157,6 +157,12 @@ class ConfigCacheTest extends MockedTest 'key1' => 'value1', 'key2' => 'value2', ], $configCache->get('system')); + + // explicit null as key + $this->assertEquals([ + 'key1' => 'value1', + 'key2' => 'value2', + ], $configCache->get('system', null)); } /** diff --git a/tests/src/Core/Config/Cache/PConfigCacheTest.php b/tests/src/Core/Config/Cache/PConfigCacheTest.php index e0e100bbac..22beccf601 100644 --- a/tests/src/Core/Config/Cache/PConfigCacheTest.php +++ b/tests/src/Core/Config/Cache/PConfigCacheTest.php @@ -79,6 +79,12 @@ class PConfigCacheTest extends MockedTest 'key1' => 'value1', 'key2' => 'value2', ], $configCache->get($uid, 'system')); + + // test explicit cat with null as key + $this->assertEquals([ + 'key1' => 'value1', + 'key2' => 'value2', + ], $configCache->get($uid, 'system', null)); } /** -- 2.39.5