Skip to content
Open
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
10 changes: 10 additions & 0 deletions system/Test/CIUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ protected function tearDown(): void

// Check for other trait methods
$this->callTraitMethods('tearDown');

$this->resetIsWindowsMock();
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
25 changes: 25 additions & 0 deletions tests/system/Test/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Loading