From ed554705e5720527a325c93e17ffbe9ed7a4e1d4 Mon Sep 17 00:00:00 2001 From: Norbert Wagner Date: Thu, 14 Jan 2021 17:48:41 +0100 Subject: [PATCH] more tests --- src/Settings.php | 5 ++--- tests/SettingsTest.php | 25 ++++++++++++++++++++++++- tests/cfg/config/site/conf.php | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Settings.php b/src/Settings.php index cdfb6e8..b663713 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -137,7 +137,7 @@ class Settings implements \Iterator else { // echo "No settingsfile: $defaultConf"; - throw new \ErrorException( "No settingsfile: $defaultConf" ); + throw new \Exception( "No settingsfile: $defaultConf" ); // throw new FileNotFoundException(); } @@ -307,7 +307,7 @@ class Settings implements \Iterator // Magic getter/setter methods {{{ public function __set( $name, $value ) { -// todo: throw new SettingsAreReadOnlyException(); + throw new \Exception("Settings are read only. Unable to set $name to $value"); } public function __get( $name ) @@ -315,7 +315,6 @@ class Settings implements \Iterator if ( !isset( $this->settings[$name] ) ) { throw new \OutOfRangeException("Setting '$name' not found"); -// todo: throw new SettingNotFoundException(); } return (is_array( $this->settings[$name] )) diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index b5b0258..967f73d 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -38,10 +38,19 @@ class SettingsTest extends TestCase public function testLoadNoFile() { $cfg = new Settings(); - $this->expectException(\ErrorException::class); + $this->expectException(\Exception::class); $cfg->load(); } + /** + */ + public function testReadOnly() + { + $cfg = new Settings(); + $this->expectException(\Exception::class); + $cfg->answer = 42; + } + /** */ private function appPath(Settings $cfg, string $dir='') @@ -86,6 +95,19 @@ class SettingsTest extends TestCase $this->assertEquals('default', $nested->testFiles); } + /** + * @depends testLoad + */ + public function testNestedArray(Settings $cfg) + { + $nested = $cfg->nested->toArray(); + $this->assertIsArray($nested); + $this->assertIsIterable($nested); + $this->assertEquals(1, $nested['level']); + $this->assertEquals(2, $nested['nested']['level']); + $this->assertEquals('default', $nested['testFiles']); + } + /** * @depends testLoad */ @@ -104,6 +126,7 @@ class SettingsTest extends TestCase $cfg = $this->appPath($cfg)->site('site')->load(); $this->assertEquals('default', $cfg->testFiles); + $this->assertEquals('site', $cfg->testFile); $this->assertEquals(42, $cfg->answer); } diff --git a/tests/cfg/config/site/conf.php b/tests/cfg/config/site/conf.php index 20f0c6a..54ad2b8 100644 --- a/tests/cfg/config/site/conf.php +++ b/tests/cfg/config/site/conf.php @@ -1,3 +1,4 @@ 42 + 'answer' => 42, + 'testFile' => 'site' ];