Carbon::setTestNow() leaks frozen clock between PHPUnit tests
0 reputation · 25 Oct 2023, 03:31 UTC
The goal is to freeze the application clock during a test suite using Carbon::setTestNow() while keeping each test isolated.
Carbon::setTestNow() sets a process-global static clock that persists until explicitly reset. Because the value is not scoped to a single request or test, a frozen time can leak into later tests when teardown does not restore the previous clock. Behavior may differ between Carbon 2.x and Carbon 3.x, and the exact reset method has not been verified against the installed vendor source.
Which method safely resets the test clock after each test without affecting parallel processes? Does Carbon\Immutable share the same global test-now state as Carbon? What assertions confirm the frozen time and test isolation in PHPUnit?