[9.x] Revert some Carbon::setTestNow() removals#41810
Conversation
7bcd3ca to
04cbc15
Compare
Without exact Carbon::now() timestamps, this causes some tests to become non-deterministic and intermittently fail if the clock's second ticks over mid-test.
04cbc15 to
d8d5d24
Compare
|
Ping @lucasmichot just FYI ^ |
|
For the record, Carbon 3 will be a bit more strict on this.
Typical case would be things like this: $repo->getStore()->shouldReceive('put')->once()->with('foo', 'bar', 602);
$result = $repo->remember('foo', Carbon::now()->addMinutes(10)->addSeconds(2), static fn () => 'bar');(see #41824) Here the moment to be chosen as the mocked "now" does not matter but it's important that the time is actually frozen during the test. Between the moment you call |
Revert about half of cleanup PR #40790 that removed "useless" calls to
Carbon::setTestNow(). Now some tests are non-deterministic and can intermittently fail for new PRs being submitted:e.g., https://github.com/laravel/framework/runs/5798854285
The mocked cache expiry was unexpectedly 1 second in the future.
Carbon::setTestNow(Carbon::now())keeps time-based mocks and assertions deterministic. Otherwise if the clock's second ticks over mid-test, assertions and mockery checks can be run on an unexpected time of day.Carbon::setTestNow(null)at the end of the test case method. If that test fails,Carbon::setTestNow(new Carbon('2018-01-01'))is now leaking into subsequent tests.try { /* assertions */ } finally { Carbon::setTestNow(null); }.