From 5ed9f75225380333812ed0046b32d6df54b1aada Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 21 Oct 2026 13:57:30 +0100 Subject: [PATCH] fix: stop the follower grouping test failing just after midnight NotificationGroupsQuery never groups follows across days, and "keeps stars and conversations apart while grouping followers" made its two follows 2 and 1 minutes before now. Run between 00:01 and 00:02 UTC, they land on different days and come back as two follow groups. The test now starts at noon. Pinning the clock wasn't enough on its own: travelTo() with a callback goes back to the real clock afterwards, so the first starAt() dropped the pin. The helpers and the two mention lines use Date::withTestNow() instead, which puts back whatever clock was set before. Co-Authored-By: Claude Opus 5.5 --- tests/Unit/Queries/NotificationGroupsQueryTest.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/Unit/Queries/NotificationGroupsQueryTest.php b/tests/Unit/Queries/NotificationGroupsQueryTest.php index 27924677d..71dce45b6 100644 --- a/tests/Unit/Queries/NotificationGroupsQueryTest.php +++ b/tests/Unit/Queries/NotificationGroupsQueryTest.php @@ -12,16 +12,17 @@ use App\Models\Notification; use App\Models\User; use App\Queries\NotificationGroupsQuery; +use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\DB; function starAt(User $user, Commit $commit, int $minutesAgo): void { - test()->travelTo(now()->subMinutes($minutesAgo), fn () => resolve(CreateCommitStar::class)->handle($user, $commit)); + Date::withTestNow(now()->subMinutes($minutesAgo), fn () => resolve(CreateCommitStar::class)->handle($user, $commit)); } function replyAt(User $user, Commit $commit, int $minutesAgo): Commit { - return test()->travelTo(now()->subMinutes($minutesAgo), function () use ($user, $commit): Commit { + return Date::withTestNow(now()->subMinutes($minutesAgo), function () use ($user, $commit): Commit { $reply = Commit::factory()->for($user)->for($commit, 'parent')->create(); resolve(CreateReplyNotifications::class)->handle($reply); @@ -32,7 +33,7 @@ function replyAt(User $user, Commit $commit, int $minutesAgo): Commit function followAt(User $follower, User $user, int $minutesAgo): void { - test()->travelTo(now()->subMinutes($minutesAgo), fn () => resolve(CreateUserFollow::class)->handle($follower, $user)); + Date::withTestNow(now()->subMinutes($minutesAgo), fn () => resolve(CreateUserFollow::class)->handle($follower, $user)); } it('groups stars per commit, newest stargazer first', function (): void { @@ -82,6 +83,7 @@ function followAt(User $follower, User $user, int $minutesAgo): void }); it('keeps stars and conversations apart while grouping followers', function (): void { + $this->travelTo(today()->setTime(12, 0)); $user = User::factory()->create(); [$first, $second] = Commit::factory()->for($user)->count(2)->create()->all(); $other = User::factory()->create(); @@ -89,8 +91,8 @@ function followAt(User $follower, User $user, int $minutesAgo): void starAt($other, $first, 7); starAt($other, $second, 6); replyAt($other, $first, 5); - $this->travelTo(now()->subMinutes(4), fn () => Notification::factory()->for($user, 'recipient')->for($other, 'actor')->mentioned()->create()); - $this->travelTo(now()->subMinutes(3), fn () => Notification::factory()->for($user, 'recipient')->for($other, 'actor')->mentioned()->create()); + Date::withTestNow(now()->subMinutes(4), fn () => Notification::factory()->for($user, 'recipient')->for($other, 'actor')->mentioned()->create()); + Date::withTestNow(now()->subMinutes(3), fn () => Notification::factory()->for($user, 'recipient')->for($other, 'actor')->mentioned()->create()); followAt($other, $user, 2); followAt(User::factory()->create(), $user, 1);