mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Convert Config to a singleton (#16349)
* Convert Config to a singleton Continuation of #14364 by @Jellyfrog This time, make the old class a shim for the facade. Will update references in a separate PR. * Remove logging config call * Apply fixes from StyleCI * Fix bad Git constructor call * Fail on config table does not exist instead of throw exception * Inline LibrenmsConfig::isRegistered() * Debug call in case there are more issues, remove before merge. * Fix up config tests * Allow config cache controlled by CONFIG_CACHE_TTL (disabled by default for now) * Enable config cache for tests * Remove debug statement and deprecation phpdoc * Apply fixes from StyleCI --------- Co-authored-by: Tony Murray <[email protected]>
This commit is contained in:
co-authored by
Tony Murray
parent
64241dbdf3
commit
f1e7a218f0
+11
-8
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* ConfigTest.php
|
||||
*
|
||||
* Tests for LibreNMS\Config
|
||||
* Tests for App\Facades\Config
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,17 +25,17 @@
|
||||
|
||||
namespace LibreNMS\Tests;
|
||||
|
||||
use App\ConfigRepository;
|
||||
use LibreNMS\Config;
|
||||
|
||||
class ConfigTest extends TestCase
|
||||
{
|
||||
private $config;
|
||||
private \ReflectionProperty $config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->config = new \ReflectionProperty(Config::class, 'config');
|
||||
$this->config->setAccessible(true);
|
||||
$this->config = new \ReflectionProperty(ConfigRepository::class, 'config');
|
||||
}
|
||||
|
||||
public function testGetBasic(): void
|
||||
@@ -46,8 +46,9 @@ class ConfigTest extends TestCase
|
||||
|
||||
public function testSetBasic(): void
|
||||
{
|
||||
$instance = $this->app->make('librenms-config');
|
||||
Config::set('basics', 'first');
|
||||
$this->assertEquals('first', $this->config->getValue()['basics']);
|
||||
$this->assertEquals('first', $this->config->getValue($instance)['basics']);
|
||||
}
|
||||
|
||||
public function testGet(): void
|
||||
@@ -137,9 +138,10 @@ class ConfigTest extends TestCase
|
||||
|
||||
public function testSet(): void
|
||||
{
|
||||
$instance = $this->app->make('librenms-config');
|
||||
Config::set('you.and.me', "I'll be there");
|
||||
|
||||
$this->assertEquals("I'll be there", $this->config->getValue()['you']['and']['me']);
|
||||
$this->assertEquals("I'll be there", $this->config->getValue($instance)['you']['and']['me']);
|
||||
}
|
||||
|
||||
public function testSetPersist(): void
|
||||
@@ -206,9 +208,10 @@ class ConfigTest extends TestCase
|
||||
*/
|
||||
private function setConfig($function)
|
||||
{
|
||||
$config = $this->config->getValue();
|
||||
$instance = $this->app->make('librenms-config');
|
||||
$config = $this->config->getValue($instance);
|
||||
$function($config);
|
||||
$this->config->setValue($config);
|
||||
$this->config->setValue($instance, $config);
|
||||
}
|
||||
|
||||
public function testForget(): void
|
||||
|
||||
Reference in New Issue
Block a user