Skip to content

Commit 0769f84

Browse files
committed
test: fix random-order failures in small components
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 6c4acef commit 0769f84

6 files changed

Lines changed: 35 additions & 1 deletion

File tree

tests/_support/Test/TestForReflectionHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public static function getStaticPrivate()
2828
return self::$static_private;
2929
}
3030

31+
public static function resetStaticPrivate(): void
32+
{
33+
self::$static_private = 'xyz';
34+
}
35+
3136
private function privateMethod($param1, $param2) // @phpstan-ignore method.unused
3237
{
3338
return 'private ' . $param1 . $param2;

tests/system/Config/BaseConfigTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function setUp(): void
4242
{
4343
parent::setUp();
4444

45+
$this->clearLooseEnvironmentOverrides();
4546
$this->fixturesFolder = __DIR__ . '/fixtures';
4647

4748
if (! class_exists('SimpleConfig', false)) {
@@ -65,12 +66,27 @@ protected function tearDown(): void
6566
{
6667
parent::tearDown();
6768

69+
$this->clearLooseEnvironmentOverrides();
6870
// This test modifies BaseConfig::$modules, so should reset.
6971
BaseConfig::reset();
7072
// This test modifies Services locator, so should reset.
7173
$this->resetServices();
7274
}
7375

76+
private function clearLooseEnvironmentOverrides(): void
77+
{
78+
foreach ([
79+
'SimpleConfig.QZERO',
80+
'SimpleConfig.QZEROSTR',
81+
'SimpleConfig.QEMPTYSTR',
82+
'SimpleConfig.QFALSE',
83+
] as $key) {
84+
putenv($key);
85+
unset($_ENV[$key]);
86+
Services::superglobals()->unsetServer($key);
87+
}
88+
}
89+
7490
public function testBasicValues(): void
7591
{
7692
$dotenv = new DotEnv($this->fixturesFolder, '.env');

tests/system/Config/FactoriesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function testPrioritizesParameterOptions(): void
244244
{
245245
Factories::setOptions('widgets', ['instanceOf' => 'stdClass']);
246246

247-
$result = Factories::widgets('OtherWidget', ['instanceOf' => null]);
247+
$result = Factories::widgets(OtherWidget::class, ['instanceOf' => null]);
248248
$this->assertInstanceOf(OtherWidget::class, $result);
249249
}
250250

tests/system/Honeypot/HoneypotTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ protected function setUp(): void
5050
{
5151
parent::setUp();
5252

53+
$this->resetServices();
54+
Factories::reset('config');
5355
Services::injectMock('superglobals', new Superglobals());
5456

5557
$this->config = new HoneypotConfig();

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,10 @@ public function testAutoRoutingLegacy(): void
671671
$config->autoRoute = true;
672672
Factories::injectMock('config', Routing::class, $config);
673673

674+
$collection = service('routes');
675+
$collection->setAutoRoute(true);
676+
$collection->setDefaultNamespace('App\Controllers');
677+
674678
$response = $this->get('home/index');
675679

676680
$response->assertOK();

tests/system/Test/ReflectionHelperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
#[Group('Others')]
2323
final class ReflectionHelperTest extends CIUnitTestCase
2424
{
25+
protected function setUp(): void
26+
{
27+
parent::setUp();
28+
29+
TestForReflectionHelper::resetStaticPrivate();
30+
}
31+
2532
public function testGetPrivatePropertyWithObject(): void
2633
{
2734
$obj = new TestForReflectionHelper();

0 commit comments

Comments
 (0)