refactor(night-contingent) : driver map batch + test cas sans heures

This commit is contained in:
2026-06-11 11:53:09 +02:00
parent a552843cec
commit 0504629ac6
2 changed files with 42 additions and 4 deletions
@@ -37,7 +37,9 @@ final class NightContingentExportBuilderTest extends TestCase
$workHourRepo->method('findByDateRangeAndEmployees')->willReturn([$whFull, $whShort]);
$contractResolver = $this->createStub(EmployeeContractResolver::class);
$contractResolver->method('resolveIsDriverForEmployeeAndDate')->willReturn(false);
$contractResolver->method('resolveIsDriverForEmployeesAndDays')->willReturn([
1 => ['2026-01-10' => false, '2026-01-11' => false],
]);
$builder = new NightContingentExportBuilder(
$workHourRepo,
@@ -68,7 +70,9 @@ final class NightContingentExportBuilderTest extends TestCase
$workHourRepo->method('findByDateRangeAndEmployees')->willReturn([$wh]);
$contractResolver = $this->createStub(EmployeeContractResolver::class);
$contractResolver->method('resolveIsDriverForEmployeeAndDate')->willReturn(true);
$contractResolver->method('resolveIsDriverForEmployeesAndDays')->willReturn([
2 => ['2026-03-05' => true],
]);
$builder = new NightContingentExportBuilder(
$workHourRepo,
@@ -82,6 +86,31 @@ final class NightContingentExportBuilderTest extends TestCase
self::assertSame(1, $rows[0]->months[3]['nightDays']); // 300 >= 240
}
public function testEmployeeWithoutWorkHoursYieldsAllZeroMonths(): void
{
$employee = $this->makeEmployee(3, 'Durand', 'Marie');
$workHourRepo = $this->createStub(WorkHourReadRepositoryInterface::class);
$workHourRepo->method('findByDateRangeAndEmployees')->willReturn([]);
$contractResolver = $this->createStub(EmployeeContractResolver::class);
$contractResolver->method('resolveIsDriverForEmployeesAndDays')->willReturn([]);
$builder = new NightContingentExportBuilder(
$workHourRepo,
$contractResolver,
new NightHoursCalculator(),
);
$rows = $builder->buildRows([$employee], 2026);
self::assertCount(1, $rows);
for ($m = 1; $m <= 12; ++$m) {
self::assertSame(0, $rows[0]->months[$m]['nightMinutes']);
self::assertSame(0, $rows[0]->months[$m]['nightDays']);
}
}
private function makeEmployee(int $id, string $last, string $first): Employee
{
$employee = new Employee();