fix(calendar) : date-only contract filter + eager-load periods for print
Review follow-ups: (1) createFromFormat('Y-m-d') keeps the current time, so a raw
DateTime comparison wrongly excluded an employee ending on the from-day (and dropped
first-day absences); normalize from/to to day bounds and compare contract periods on
date only (Y-m-d), mirroring the calendar view. (2) eager-load contractPeriods in
findForPrintBySiteIds to avoid an N+1 during filtering. Added a boundary test.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,21 @@ final class AbsencePrintProviderTest extends TestCase
|
||||
self::assertFalse($this->hasInRange($provider, $employee, '2026-05-01', '2026-05-31'));
|
||||
}
|
||||
|
||||
public function testHasContractInRangeIncludesEmployeeEndingOnFromDayDespiteTimeComponent(): void
|
||||
{
|
||||
// Garde-fou : `from` portant une heure (cf. createFromFormat) ne doit pas exclure
|
||||
// un employé dont le contrat finit pile le jour de `from` (comparaison date seule).
|
||||
$provider = new ReflectionClass(AbsencePrintProvider::class)->newInstanceWithoutConstructor();
|
||||
$employee = $this->buildEmployeeWithPeriod('2025-01-01', '2026-05-01');
|
||||
|
||||
$result = new ReflectionClass($provider::class)
|
||||
->getMethod('hasContractInRange')
|
||||
->invoke($provider, $employee, new DateTimeImmutable('2026-05-01 08:33:53'), new DateTimeImmutable('2026-05-31 23:59:59'))
|
||||
;
|
||||
|
||||
self::assertTrue($result);
|
||||
}
|
||||
|
||||
private function hasInRange(object $provider, Employee $employee, string $from, string $to): bool
|
||||
{
|
||||
return new ReflectionClass($provider::class)
|
||||
|
||||
Reference in New Issue
Block a user