From 81c9247571c5fbfaedf2baf0f80a1036227320fa Mon Sep 17 00:00:00 2001 From: Norbert Wagner Date: Thu, 14 Jan 2021 13:53:02 +0100 Subject: [PATCH] test Exceptions --- src/Settings.php | 2 +- tests/SettingsTest.php | 11 +++++++++++ tests/cfg/config/default.conf.php | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Settings.php b/src/Settings.php index 533999d..cdfb6e8 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -314,7 +314,7 @@ class Settings implements \Iterator { if ( !isset( $this->settings[$name] ) ) { - throw new \Exception("Setting '$name' not found"); + throw new \OutOfRangeException("Setting '$name' not found"); // todo: throw new SettingNotFoundException(); } diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 5147386..b5b0258 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -82,9 +82,20 @@ class SettingsTest extends TestCase $this->assertIsObject($nested); $this->assertIsIterable($nested); $this->assertEquals(1, $nested->level); + $this->assertEquals(2, $nested->nested->level); $this->assertEquals('default', $nested->testFiles); } + /** + * @depends testLoad + */ + public function testSettingNotFound(Settings $cfg) + { + $this->assertEquals('default', $cfg->testFiles); + $this->expectException(\OutOfRangeException::class); + $cfg->keyDoesNotExist; + } + /** */ public function testSiteOverride() diff --git a/tests/cfg/config/default.conf.php b/tests/cfg/config/default.conf.php index 769fe7e..ae32501 100644 --- a/tests/cfg/config/default.conf.php +++ b/tests/cfg/config/default.conf.php @@ -6,5 +6,9 @@ [ 'level' => 1, 'testFiles' => 'default', + 'nested' => + [ + 'level' => 2 + ] ] ];