Skip to content

Commit edf4380

Browse files
authored
fix: reset is_windows() mock state in CIUnitTestCase::tearDown() (#10554)
1 parent 13a35f7 commit edf4380

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎system/Test/CIUnitTestCase.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ protected function tearDown(): void
273273

274274
// Check for other trait methods
275275
$this->callTraitMethods('tearDown');
276+
277+
$this->resetIsWindowsMock();
276278
}
277279

278280
/**
@@ -318,6 +320,14 @@ protected function resetServices(bool $initAutoloader = true)
318320
Services::reset($initAutoloader);
319321
}
320322

323+
/**
324+
* Resets the mocked is_windows() function back to default state.
325+
*/
326+
protected function resetIsWindowsMock(): void
327+
{
328+
is_windows(null);
329+
}
330+
321331
/**
322332
* Injects the mock Cache driver to prevent filesystem collisions.
323333
*

‎tests/system/CommonFunctionsTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ public function testIsWindowsUsingMock(): void
863863
$this->assertFalse(is_windows());
864864
$this->assertNotTrue(is_windows());
865865

866-
is_windows();
866+
is_windows(null);
867867
$this->assertSame(str_contains(php_uname(), 'Windows'), is_windows());
868868
$this->assertSame(defined('PHP_WINDOWS_VERSION_MAJOR'), is_windows());
869869
}

‎tests/system/Test/TestCaseTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,29 @@ public function testCloseEnoughStringBadLength(): void
9393
$result = $this->assertCloseEnoughString('apples & oranges', 'apples');
9494
$this->assertFalse($result, 'Different string lengths should have returned false');
9595
}
96+
97+
public function testTearDownResetsIsWindowsMock(): void
98+
{
99+
$testCase = new class ('test') extends CIUnitTestCase {
100+
protected $tearDownMethods = ['customTearDown'];
101+
102+
protected function customTearDown(): void
103+
{
104+
}
105+
106+
public function triggerTearDown(): void
107+
{
108+
$this->tearDown();
109+
}
110+
};
111+
112+
$default = DIRECTORY_SEPARATOR === '\\';
113+
114+
is_windows(! $default);
115+
$this->assertSame(! $default, is_windows());
116+
117+
$testCase->triggerTearDown();
118+
119+
$this->assertSame($default, is_windows());
120+
}
96121
}

0 commit comments

Comments
 (0)