Skip to content

Commit

Permalink
Merge pull request #8095 from kenjis/test-fix-BaseConfigTest
Browse files Browse the repository at this point in the history
test: fix BaseConfigTest
  • Loading branch information
kenjis authored Oct 26, 2023
2 parents 7cd5c99 + f42244f commit 6c788de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
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

0 comments on commit 6c788de

Please sign in to comment.