From cb4ddbe4e76c81a50748fc3869225f16d9ce13f0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 25 Jan 2018 19:55:31 +0100 Subject: [PATCH] Fix warnings when upgrading from legacy SebSauvage version Fixes #1040 --- application/config/ConfigPhp.php | 6 +++--- tests/config/ConfigPhpTest.php | 14 ++++++++++++++ tests/utils/config/emptyConfigPhp.php | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/utils/config/emptyConfigPhp.php diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php index 2f66e8e0..8add8bcd 100644 --- a/application/config/ConfigPhp.php +++ b/application/config/ConfigPhp.php @@ -83,10 +83,10 @@ public function read($filepath) $out = array(); foreach (self::$ROOT_KEYS as $key) { - $out[$key] = $GLOBALS[$key]; + $out[$key] = isset($GLOBALS[$key]) ? $GLOBALS[$key] : ''; } - $out['config'] = $GLOBALS['config']; - $out['plugins'] = !empty($GLOBALS['plugins']) ? $GLOBALS['plugins'] : array(); + $out['config'] = isset($GLOBALS['config']) ? $GLOBALS['config'] : []; + $out['plugins'] = isset($GLOBALS['plugins']) ? $GLOBALS['plugins'] : []; return $out; } diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index abfbb305..be23eea1 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php @@ -36,6 +36,20 @@ public function testReadNonExistent() $this->assertEquals(array(), $this->configIO->read('nope')); } + /** + * Read an empty existent config file -> array with blank default values. + */ + public function testReadEmpty() + { + $dataFile = 'tests/utils/config/emptyConfigPhp.php'; + $conf = $this->configIO->read($dataFile); + $this->assertEmpty($conf['login']); + $this->assertEmpty($conf['title']); + $this->assertEmpty($conf['titleLink']); + $this->assertEmpty($conf['config']); + $this->assertEmpty($conf['plugins']); + } + /** * Write a new config file. */ diff --git a/tests/utils/config/emptyConfigPhp.php b/tests/utils/config/emptyConfigPhp.php new file mode 100644 index 00000000..b3d9bbc7 --- /dev/null +++ b/tests/utils/config/emptyConfigPhp.php @@ -0,0 +1 @@ +