diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 0269194bdc4c..7daa6e1544c0 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -55,7 +55,7 @@ class BaseConfig /** * The modules configuration. * - * @var Modules + * @var Modules|null */ protected static $moduleConfig; @@ -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; diff --git a/tests/system/Config/BaseConfigTest.php b/tests/system/Config/BaseConfigTest.php index ca615602a276..76861ccb12ad 100644 --- a/tests/system/Config/BaseConfigTest.php +++ b/tests/system/Config/BaseConfigTest.php @@ -50,6 +50,7 @@ protected function setUp(): void } BaseConfig::$registrars = []; + BaseConfig::setModules(new Modules()); // reset to clean copy of Modules } public function testBasicValues(): void @@ -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); }