Skip to content

Commit

Permalink
Added createFromArray method on SettingsFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Jun 10, 2022
1 parent 4d8e849 commit 657e956
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Settings/SettingsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions tests/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit 657e956

Please sign in to comment.