contractQuery()->getDQL(); $this->assertStringContainsString('document IS NULL', $dql); $this->assertStringContainsString('disposition.createdAt >= :dayStart', $dql); $this->assertStringContainsString('disposition.createdAt < :dayEnd', $dql); $this->assertStringNotContainsString('document.createdAt', $dql); } /** * disposition.createdAt is a timestamp and the cron runs at 01:00, so an equality would only * ever match a disposition created at that exact second. */ public function testContractReminderUsesAHalfOpenDayRange(): void { $query = $this->contractQuery(5); $dayStart = $query->getParameter('dayStart')->getValue(); $dayEnd = $query->getParameter('dayEnd')->getValue(); $this->assertSame('00:00:00', $dayStart->format('H:i:s')); $this->assertSame( (new \DateTimeImmutable('today'))->modify('-5 days')->format('Y-m-d'), $dayStart->format('Y-m-d') ); $this->assertSame('1', $dayStart->diff($dayEnd)->format('%a')); $this->assertDoesNotMatchRegularExpression('/disposition\.createdAt = :/', $query->getDQL()); } /** * An unfiltered join would let any other upload - a driver's licence, say - stand in for the * contract and suppress the reminder. */ public function testContractReminderOnlyJoinsTheContract(): void { $query = $this->contractQuery(); $this->assertStringContainsString('WITH document.type = :documentType', $query->getDQL()); $this->assertSame(Upload::TYPE_CONTRACT, $query->getParameter('documentType')->getValue()); } public function testContractReminderSkipsDeadAssignmentsAndDeletedTeamers(): void { $query = $this->contractQuery(); $dql = $query->getDQL(); $this->assertStringContainsString('teamer.deletedAt IS NULL', $dql); $this->assertStringContainsString('disposition.status = :dispositionStatus', $dql); $this->assertStringContainsString('assignment.status NOT IN(:assignmentStatus)', $dql); $this->assertSame(Disposition::STATUS_NEW, $query->getParameter('dispositionStatus')->getValue()); $this->assertSame( [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED], $query->getParameter('assignmentStatus')->getValue() ); } /** * The bug that killed this query: destination.dateTo and assignment.dateTo are DATE columns, * and Doctrine binds a DateTimeImmutable as 'Y-m-d H:i:s', which a DATE never equals. */ public function testInvoiceReminderBindsADateAndNotATimestamp(): void { $value = $this ->invoiceQuery(new \DateTimeImmutable('2026-03-15 01:00:05')) ->getParameter('endDate') ->getValue() ; $this->assertSame('2026-03-15', $value); } /** * Without the IS NULL guard on the second branch, an assignment that moves the end date into * the future still matches on its destination's date. */ public function testInvoiceReminderGuardsTheDestinationFallback(): void { $dql = $this->invoiceQuery()->getDQL(); $this->assertStringContainsString( 'assignment.dateTo IS NOT NULL AND assignment.dateTo = :endDate', $dql ); $this->assertStringContainsString( 'assignment.dateTo IS NULL AND destination.dateTo = :endDate', $dql ); } public function testInvoiceReminderOnlyJoinsTheInvoiceAndSkipsFinishedDispositions(): void { $query = $this->invoiceQuery(); $dql = $query->getDQL(); $this->assertStringContainsString('WITH document.type = :documentType', $dql); $this->assertStringContainsString('document IS NULL', $dql); $this->assertStringContainsString('teamer.deletedAt IS NULL', $dql); $this->assertSame(Upload::TYPE_INVOICE, $query->getParameter('documentType')->getValue()); $this->assertSame( [Disposition::STATUS_CALLED_OFF, Disposition::STATUS_COMPLETED], $query->getParameter('dispositionStatus')->getValue() ); } private function contractQuery(int $deadlineDays = 5): Query { return $this->repository()->getContractReminderQuery($deadlineDays); } private function invoiceQuery(?\DateTimeImmutable $endDate = null): Query { return $this ->repository() ->getInvoiceReminderQuery($endDate ?? new \DateTimeImmutable('2026-03-15')) ; } private function repository(): DispositionRepository { /** @var EntityManagerInterface $entityManager */ $entityManager = static::getContainer()->get(EntityManagerInterface::class); /** @var DispositionRepository $repository */ $repository = $entityManager->getRepository(Disposition::class); return $repository; } }