diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index d86e543a9a61..05e4c647f0ed 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -273,6 +273,8 @@ protected function tearDown(): void // Check for other trait methods $this->callTraitMethods('tearDown'); + + $this->resetIsWindowsMock(); } /** @@ -318,6 +320,14 @@ protected function resetServices(bool $initAutoloader = true) Services::reset($initAutoloader); } + /** + * Resets the mocked is_windows() function back to default state. + */ + protected function resetIsWindowsMock(): void + { + is_windows(null); + } + /** * Injects the mock Cache driver to prevent filesystem collisions. * diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index b4901a5e8d93..f1ce25c04aa1 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -863,7 +863,7 @@ public function testIsWindowsUsingMock(): void $this->assertFalse(is_windows()); $this->assertNotTrue(is_windows()); - is_windows(); + is_windows(null); $this->assertSame(str_contains(php_uname(), 'Windows'), is_windows()); $this->assertSame(defined('PHP_WINDOWS_VERSION_MAJOR'), is_windows()); } diff --git a/tests/system/Test/TestCaseTest.php b/tests/system/Test/TestCaseTest.php index 6905d825533a..611c3fe0ebd4 100644 --- a/tests/system/Test/TestCaseTest.php +++ b/tests/system/Test/TestCaseTest.php @@ -93,4 +93,29 @@ public function testCloseEnoughStringBadLength(): void $result = $this->assertCloseEnoughString('apples & oranges', 'apples'); $this->assertFalse($result, 'Different string lengths should have returned false'); } + + public function testTearDownResetsIsWindowsMock(): void + { + $testCase = new class ('test') extends CIUnitTestCase { + protected $tearDownMethods = ['customTearDown']; + + protected function customTearDown(): void + { + } + + public function triggerTearDown(): void + { + $this->tearDown(); + } + }; + + $default = DIRECTORY_SEPARATOR === '\\'; + + is_windows(! $default); + $this->assertSame(! $default, is_windows()); + + $testCase->triggerTearDown(); + + $this->assertSame($default, is_windows()); + } }