Skip to content

[12.x] Fix callable type for freezeTime, freezeSecond, and travelTo - #59466

Merged
taylorotwell merged 3 commits into
laravel:12.xfrom
nbayramberdiyev:fix/interacts-with-time-callback-type
Mar 31, 2026
Merged

taylorotwell merged 3 commits into
laravel:12.xfrom
nbayramberdiyev:fix/interacts-with-time-callback-type

Conversation

@nbayramberdiyev

@nbayramberdiyev nbayramberdiyev commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

This fixes the callable parameter type in the docblocks of freezeTime(), freezeSecond(), and travelTo() in the InteractsWithTime trait.

Since #58951, the callback parameter is typed as (callable(): TReturn)|null, a callable accepting zero parameters. However, travelTo() actually invokes the callback with $date:

return tap($callback($date), function () {
    Carbon::setTestNow();
});

This causes PHPStan/Larastan to report a false positive when passing a closure that accepts a Carbon parameter:

$this->freezeTime(function (Carbon $date) {
    // ...
});
Parameter #1 $callback of method Illuminate\Foundation\Testing\TestCase::freezeTime()
expects (callable(): void)|null, Closure(Illuminate\Support\Carbon): void given.

The fix updates the callable types to reflect the actual runtime behavior:

  • freezeTime / freezeSecond: (callable(\Illuminate\Support\Carbon): TReturn)|null
  • travelTo: uses a TDate template inferred from the $date parameter, so the callback type matches dynamically

Comment thread src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php Outdated
@nbayramberdiyev
nbayramberdiyev requested a review from calebdw March 31, 2026 11:14
@calebdw

calebdw commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Looks good!

@taylorotwell
taylorotwell merged commit 0d3fc77 into laravel:12.x Mar 31, 2026
70 checks passed
@nbayramberdiyev
nbayramberdiyev deleted the fix/interacts-with-time-callback-type branch March 31, 2026 14:53
jonagoldman pushed a commit to deplox/laravel-framework that referenced this pull request Apr 30, 2026
…aravel#59466)

* Fix callable type for freezeTime, freezeSecond, and travelTo callbacks

* Remove travelTo type test with narrowed Carbon callback

* Use template for travelTo callback date type
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 1, 2026
Port callback return templates across Wormhole and InteractsWithTime, including the later correction that describes the date passed to freeze and travel callbacks. Use CarbonInterface for configurable Date factory output and infer the exact supplied travelTo date type.

Add native types for the documented inputs and explicit null returns for paths without callbacks. Retain Hypervel’s immutable date defaults, coroutine-local clock, and finally-based cleanup when callbacks throw. Port both complete upstream type fixtures and cover concrete date and string inference without adding redundant runtime tests.

Upstream:
laravel/framework#58951
laravel/framework#59466
Source: laravel/framework 13.x at 01d008c9b5f32cb7c5e50a9a22273113d810b2a2.

Validation: each type fixture after porting, existing time-travel tests through ParaTest, full source and type analysis, formatting, and post-format type checks pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants