diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d95cfeb..c8fda17e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `ray` will be documented in this file +## Unreleased +### Added +- Added a `createFromArray()` method on the `SettingsFactory`. + ## 1.34.5 - 2022-06-03 ### What's Changed diff --git a/src/Settings/SettingsFactory.php b/src/Settings/SettingsFactory.php index 9c661c20..7c64446a 100644 --- a/src/Settings/SettingsFactory.php +++ b/src/Settings/SettingsFactory.php @@ -6,11 +6,16 @@ class SettingsFactory { public static $cache = []; + public static function createFromArray(array $settings = []): Settings + { + return new Settings($settings); + } + public static function createFromConfigFile(string $configDirectory = null): Settings { $settingValues = (new static())->getSettingsFromConfigFile($configDirectory); - $settings = new Settings($settingValues); + $settings = static::createFromArray($settingValues); if (count($settingValues)) { $settings->markAsLoadedUsingSettingsFile(); diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 1bb8a715..b33aeb5d 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -44,6 +44,15 @@ public function it_can_find_the_settings_file_more_than_once() $this->assertEquals('http://otherhost', $settings2->host); } + /** @test */ + public function it_can_create_settings_from_an_Array() + { + $settings = SettingsFactory::createFromArray(['enabled' => false, 'port' => 1234]); + + self::assertFalse($settings->enabled); + self::assertSame(1234, $settings->port); + } + protected function skipOnGitHubActions(): void { if (getenv('CI')) {