Skip to content

Commit d328eac

Browse files
committed
Use static setter
1 parent 3773743 commit d328eac

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

system/Config/BaseConfig.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BaseConfig
5555
/**
5656
* The modules configuration.
5757
*
58-
* @var Modules
58+
* @var Modules|null
5959
*/
6060
protected static $moduleConfig;
6161

@@ -74,15 +74,24 @@ public static function __set_state(array $array)
7474
return $obj;
7575
}
7676

77+
/**
78+
* @internal For testing purposes only.
79+
* @testTag
80+
*/
81+
public static function setModules(Modules $modules): void
82+
{
83+
static::$moduleConfig = $modules;
84+
}
85+
7786
/**
7887
* Will attempt to get environment variables with names
7988
* that match the properties of the child class.
8089
*
8190
* The "shortPrefix" is the lowercase-only config class name.
8291
*/
83-
public function __construct(?Modules $modules = null)
92+
public function __construct()
8493
{
85-
static::$moduleConfig = $modules ?? new Modules();
94+
static::$moduleConfig ??= new Modules();
8695

8796
if (! static::$override) {
8897
return;

tests/system/Config/BaseConfigTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function setUp(): void
5050
}
5151

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

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

279-
$config = new RegistrarConfig($modules);
280+
RegistrarConfig::setModules($modules);
281+
$config = new RegistrarConfig();
280282

281283
$this->assertSame([], $config::$registrars);
282284
}

0 commit comments

Comments
 (0)