Added string type-hint for get() and a test case for it

This commit is contained in:
Philipp Holzer 2019-07-14 23:23:20 +02:00
parent aa249adf6d
commit 4af08d82b2
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
4 changed files with 14 additions and 2 deletions

View file

@ -68,7 +68,7 @@ class ConfigCache
* *
* @return null|mixed Returns the value of the Config entry or null if not set * @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])) { if (isset($this->config[$cat][$key])) {
return $this->config[$cat][$key]; return $this->config[$cat][$key];

View file

@ -62,7 +62,7 @@ class PConfigCache
* *
* @return null|string The value of the config entry or null if not set * @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])) { if (isset($this->config[$uid][$cat][$key])) {
return $this->config[$uid][$cat][$key]; return $this->config[$uid][$cat][$key];

View file

@ -157,6 +157,12 @@ class ConfigCacheTest extends MockedTest
'key1' => 'value1', 'key1' => 'value1',
'key2' => 'value2', 'key2' => 'value2',
], $configCache->get('system')); ], $configCache->get('system'));
// explicit null as key
$this->assertEquals([
'key1' => 'value1',
'key2' => 'value2',
], $configCache->get('system', null));
} }
/** /**

View file

@ -79,6 +79,12 @@ class PConfigCacheTest extends MockedTest
'key1' => 'value1', 'key1' => 'value1',
'key2' => 'value2', 'key2' => 'value2',
], $configCache->get($uid, 'system')); ], $configCache->get($uid, 'system'));
// test explicit cat with null as key
$this->assertEquals([
'key1' => 'value1',
'key2' => 'value2',
], $configCache->get($uid, 'system', null));
} }
/** /**