Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ public static function setModules(Modules $modules): void
static::$moduleConfig = $modules;
}

/**
* @internal For testing purposes only.
* @testTag
*/
public static function reset(): void
{
static::$registrars = [];
static::$override = true;
static::$didDiscovery = false;
static::$moduleConfig = null;
}

/**
* Will attempt to get environment variables with names
* that match the properties of the child class.
Expand Down
21 changes: 18 additions & 3 deletions tests/system/Config/BaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ protected function setUp(): void
require $this->fixturesFolder . '/Encryption.php';
}

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

protected function tearDown(): void
{
parent::tearDown();

// This test modifies BaseConfig::$modules, so should reset.
BaseConfig::reset();
// This test modifies Services locator, so should reset.
$this->resetServices();
}

public function testBasicValues(): void
Expand Down Expand Up @@ -271,18 +280,24 @@ public function testBadRegistrar(): void
$this->assertSame('bar', $config->foo);
}

/**
* @psalm-suppress UndefinedClass
*/
public function testDiscoveryNotEnabledWillNotPopulateRegistrarsArray(): void
{
/** @var MockObject&Modules $modules */
$modules = $this->createMock(Modules::class);
$modules->method('shouldDiscover')->with('registrars')->willReturn(false);

RegistrarConfig::setModules($modules);

$config = new RegistrarConfig();

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

/**
* @psalm-suppress UndefinedClass
*/
public function testRedoingDiscoveryWillStillSetDidDiscoveryPropertyToTrue(): void
{
/** @var FileLocator&MockObject $locator */
Expand Down