diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-27 20:18:22 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-27 20:18:22 +0300 |
| commit | c2ce4528c4b671466291f7947c682b4adffa007f (patch) | |
| tree | eb4493ea9ee34e44b351a46e9883bbb4405768f3 /classes | |
| parent | 0d83f0350991a0993234278ff822a5a9893802f5 (diff) | |
| download | the-epube-c2ce4528c4b671466291f7947c682b4adffa007f.tar.gz the-epube-c2ce4528c4b671466291f7947c682b4adffa007f.tar.xz | |
add some simple tests
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/Config.php | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/classes/Config.php b/classes/Config.php index f7d8638..1129117 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -66,7 +66,8 @@ class Config { // } - function __construct() { + /** load data from environment variables */ + function reload(): void { $ref = new ReflectionClass(get_class($this)); foreach ($ref->getConstants() as $const => $cvalue) { @@ -75,11 +76,34 @@ class Config { list ($defval, $deftype) = self::_DEFAULTS[$const]; - $this->params[$cvalue] = [ self::cast_to(!empty($override) ? $override : $defval, $deftype), $deftype ]; + $this->params[$cvalue] = [ self::cast_to($override !== false ? $override : $defval, $deftype), $deftype ]; } } } + /** this is primarily needed for tests, normally global config is not changed at runtime */ + static function set(string $key, mixed $value): bool { + if (!getenv('IS_INTEGRATION_TESTING') && !getenv('IS_TESTING')) { + user_error("This method is only available for tests.", E_USER_WARNING); + + return false; + } if (array_key_exists($key, self::_DEFAULTS)) { + list ($defval, $deftype) = self::_DEFAULTS[$key]; + + self::get_instance()->params[$key] = [self::cast_to($value, $deftype), $deftype]; + + return true; + } else { + user_error("Requested to set unknown global config variable: {$key}", E_USER_WARNING); + + return false; + } + } + + function __construct() { + $this->reload(); + } + /* package maintainers who don't use git: if version_static.txt exists in tt-rss root directory, its contents are displayed instead of git commit-based version, this could be generated based on source git tree commit used when creating the package */ |
