query(dateFrom: new \DateTimeImmutable('2026-07-01'))->getDQL(); $this->assertStringContainsString('destination.dateFrom >= :dateFrom', $dql); $this->assertStringNotContainsString('event.occurredAt', $dql); } /** * The season is the destination's date range, the convention shared with SeasonPeriodFilter. */ public function testTheSeasonIsTheDestinationDateRange(): void { $dql = $this->query( dateFrom: new \DateTimeImmutable('2026-07-01'), dateTo: new \DateTimeImmutable('2027-06-30'), )->getDQL(); $this->assertStringContainsString('destination.dateFrom >= :dateFrom', $dql); $this->assertStringContainsString('destination.dateTo <= :dateTo', $dql); } /** * The dimension columns are plain integers, not relations, so the assignment is only * reachable through an arbitrary join. */ public function testTheSeasonReachesTheAssignmentThroughAnArbitraryJoin(): void { $dql = $this->query(dateFrom: new \DateTimeImmutable('2026-07-01'))->getDQL(); $this->assertStringContainsString('assignment.id = event.assignmentId', $dql); } public function testOccurrenceAsksWhenTheEventWasRecordedAndJoinsNothing(): void { $dql = $this->query( dateFrom: new \DateTimeImmutable('2026-07-01'), dateBasis: StatisticsDateBasis::OCCURRENCE, )->getDQL(); $this->assertStringContainsString('event.occurredAt >= :dateFrom', $dql); $this->assertStringNotContainsString('JOIN', $dql); } /** * An unfiltered count spans every season there is, so there is nothing to join for. */ public function testNoPeriodMeansNoJoinEitherWay(): void { $this->assertStringNotContainsString('JOIN', $this->query()->getDQL()); } public function testTheGroupingColumnStaysWhitelisted(): void { $this->expectException(\InvalidArgumentException::class); $this->query(dimension: 'payload'); } private function query( string $dimension = 'hotelCode', ?\DateTimeImmutable $dateFrom = null, ?\DateTimeImmutable $dateTo = null, StatisticsDateBasis $dateBasis = StatisticsDateBasis::SEASON, ): Query { return $this->repository()->getCountGroupedByQuery( StatisticsEventName::APPLICATION_CREATED, $dimension, $dateFrom, $dateTo, $dateBasis, ); } private function repository(): StatisticsEventRepository { /** @var EntityManagerInterface $entityManager */ $entityManager = static::getContainer()->get(EntityManagerInterface::class); /** @var StatisticsEventRepository $repository */ $repository = $entityManager->getRepository(StatisticsEvent::class); return $repository; } }