create([ 'matricule' => new Matricule($matricule), 'code' => new Code($code), 'nom' => 'Dupont', 'prenom' => 'Jean', 'start_date' => $startDate, 'end_date' => $endDate, 'etablissement' => new ShopperEstablishmentCode('ETAB01'), 'site' => new ShopperSiteCode('SITE'), 'service' => new ShopperServiceCode('101'), ]); }; it('evaluates is_active and active scope consistently across start_date and end_date', function () use ($createEmployee): void { // GIVEN $frozenNow = Date::parse('2026-11-15 10:00:00'); Date::setTestNow($frozenNow); try { $activeNoDates = $createEmployee('1000001', 'ABCDEF1', null, null); $activeStartedToday = $createEmployee('1000002', 'ABCDEF2', '2026-11-15', null); $activeInWindow = $createEmployee('1000003', 'ABCDEF3', '2026-11-01', '2026-11-16'); $inactiveFutureStart = $createEmployee('1000004', 'ABCDEF4', '2026-11-16', null); $inactiveFutureBoth = $createEmployee('1000005', 'ABCDEF5', '2026-11-16', '2026-11-30'); $inactiveEndedToday = $createEmployee('1000006', 'ABCDEF6', '2026-11-01', '2026-11-15'); $inactiveEndedPast = $createEmployee('1000007', 'ABCDEF7', '2026-11-01', '2026-11-14'); // WHEN $activeIds = Employee::query() ->active() ->pluck('id') ->all(); // THEN expect($activeNoDates->is_active)->toBeTrue() ->and($activeStartedToday->is_active)->toBeTrue() ->and($activeInWindow->is_active)->toBeTrue() ->and($inactiveFutureStart->is_active)->toBeFalse() ->and($inactiveFutureBoth->is_active)->toBeFalse() ->and($inactiveEndedToday->is_active)->toBeFalse() ->and($inactiveEndedPast->is_active)->toBeFalse() ->and($activeIds)->toEqualCanonicalizing([ $activeNoDates->id, $activeStartedToday->id, $activeInWindow->id, ]); } finally { Date::setTestNow(); } }); it('uses Europe/Paris day boundaries for is_active and active scope when UTC date is previous day', function () use ($createEmployee): void { // GIVEN: 2026-05-07 22:30:00 UTC === 2026-05-08 00:30:00 Europe/Paris Date::setTestNow(Date::parse('2026-05-07 22:30:00', 'UTC')); try { $startedAtParisMidnight = $createEmployee('2000001', 'ABCDEF8', '2026-05-08', null); $endedAtParisMidnight = $createEmployee('2000002', 'ABCDEF9', '2026-05-01', '2026-05-08'); // WHEN $activeIds = Employee::query()->active()->pluck('id')->all(); // THEN expect($startedAtParisMidnight->is_active)->toBeTrue() ->and($endedAtParisMidnight->is_active)->toBeFalse() ->and($activeIds)->toContain($startedAtParisMidnight->id) ->and($activeIds)->not->toContain($endedAtParisMidnight->id); } finally { Date::setTestNow(); } }); });