Skip to content

Commit

Permalink
Use static setter
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Oct 25, 2023
1 parent 89f1cc6 commit 3142108
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BaseConfig
/**
* The modules configuration.
*
* @var Modules
* @var Modules|null
*/
protected static $moduleConfig;

Expand All @@ -74,15 +74,24 @@ public static function __set_state(array $array)
return $obj;
}

/**
* @internal For testing purposes only.
* @testTag
*/
public static function setModules(Modules $modules): void
{
static::$moduleConfig = $modules;
}

/**
* Will attempt to get environment variables with names
* that match the properties of the child class.
*
* The "shortPrefix" is the lowercase-only config class name.
*/
public function __construct(?Modules $modules = null)
public function __construct()
{
static::$moduleConfig = $modules ?? new Modules();
static::$moduleConfig ??= new Modules();

if (! static::$override) {
return;
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Config/BaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function setUp(): void
}

BaseConfig::$registrars = [];
BaseConfig::setModules(new Modules()); // reset to clean copy of Modules
}

public function testBasicValues(): void
Expand Down Expand Up @@ -276,7 +277,8 @@ public function testDiscoveryNotEnabledWillNotPopulateRegistrarsArray(): void
$modules = $this->createMock(Modules::class);
$modules->method('shouldDiscover')->with('registrars')->willReturn(false);

$config = new RegistrarConfig($modules);
RegistrarConfig::setModules($modules);
$config = new RegistrarConfig();

$this->assertSame([], $config::$registrars);
}
Expand Down

0 comments on commit 3142108

Please sign in to comment.