Skip to content

Commit 6c788de

Browse files
authored
Merge pull request #8095 from kenjis/test-fix-BaseConfigTest
test: fix BaseConfigTest
2 parents 7cd5c99 + f42244f commit 6c788de

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

system/Config/BaseConfig.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public static function setModules(Modules $modules): void
8383
static::$moduleConfig = $modules;
8484
}
8585

86+
/**
87+
* @internal For testing purposes only.
88+
* @testTag
89+
*/
90+
public static function reset(): void
91+
{
92+
static::$registrars = [];
93+
static::$override = true;
94+
static::$didDiscovery = false;
95+
static::$moduleConfig = null;
96+
}
97+
8698
/**
8799
* Will attempt to get environment variables with names
88100
* that match the properties of the child class.

tests/system/Config/BaseConfigTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ protected function setUp(): void
4949
require $this->fixturesFolder . '/Encryption.php';
5050
}
5151

52-
BaseConfig::$registrars = [];
53-
BaseConfig::setModules(new Modules()); // reset to clean copy of Modules
52+
BaseConfig::reset();
53+
}
54+
55+
protected function tearDown(): void
56+
{
57+
parent::tearDown();
58+
59+
// This test modifies BaseConfig::$modules, so should reset.
60+
BaseConfig::reset();
61+
// This test modifies Services locator, so should reset.
62+
$this->resetServices();
5463
}
5564

5665
public function testBasicValues(): void
@@ -271,18 +280,24 @@ public function testBadRegistrar(): void
271280
$this->assertSame('bar', $config->foo);
272281
}
273282

283+
/**
284+
* @psalm-suppress UndefinedClass
285+
*/
274286
public function testDiscoveryNotEnabledWillNotPopulateRegistrarsArray(): void
275287
{
276288
/** @var MockObject&Modules $modules */
277289
$modules = $this->createMock(Modules::class);
278290
$modules->method('shouldDiscover')->with('registrars')->willReturn(false);
279-
280291
RegistrarConfig::setModules($modules);
292+
281293
$config = new RegistrarConfig();
282294

283295
$this->assertSame([], $config::$registrars);
284296
}
285297

298+
/**
299+
* @psalm-suppress UndefinedClass
300+
*/
286301
public function testRedoingDiscoveryWillStillSetDidDiscoveryPropertyToTrue(): void
287302
{
288303
/** @var FileLocator&MockObject $locator */

0 commit comments

Comments
 (0)