destinationRepository = $this->createMock(DestinationRepository::class); $this->userRepository = $this->createMock(UserRepository::class); $this->mailer = $this->createMock(Mailer::class); $this->service = new FeedbackReminderService( $this->destinationRepository, $this->userRepository, $this->mailer, new NullLogger(), '2026-11-11' ); } /** * Their own hotel codes and their own teamer, so their own placement on a travel is never * among what they are reminded of; travels ended yesterday or earlier. */ public function testEachHouseManagerIsAskedAboutWithTheirOwnCodesAndTeamer(): void { $houseManager = $this->houseManager('anna@example.org', ['DKI']); $this->userRepository->method('findHouseManagersToRemind')->willReturn([$houseManager]); $this->destinationRepository ->expects($this->once()) ->method('findPendingForHouseManager') ->with($houseManager, new \DateTimeImmutable('2026-11-11'), new \DateTimeImmutable('2026-11-19')) ->willReturn([]) ; $this->assertSame('Sent feedback reminders to 0 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY.' 01:00'))); } public function testMutedHouseManagersAndThoseWithoutHotelCodesAreSkipped(): void { $this->userRepository->method('findHouseManagersToRemind')->willReturn([ $this->houseManager('muted@example.org', ['DKI'])->setMuteNotifications(true), $this->houseManager('nohouse@example.org', []), ]); $this->destinationRepository->expects($this->never())->method('findPendingForHouseManager'); $this->mailer->expects($this->never())->method('createAndSendEmail'); // skipped ones are not counted as reminded $this->assertSame('Sent feedback reminders to 0 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY))); } /** * The teamer reminder's pace: nothing is due on night 10, so no mail, though the travel is * still pending. */ public function testNoMailOnANightNothingIsDue(): void { $this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('anna@example.org', ['DKI'])]); $this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($this->travel(10))]); $this->mailer->expects($this->never())->method('createAndSendEmail'); $this->assertSame('Sent feedback reminders to 0 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY))); } /** * One travel due tonight brings the whole list along, the one on its quiet night 10 included. */ public function testADueTravelBringsTheWholeListAlong(): void { $due = $this->travel(14); $quiet = $this->travel(10); $this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('anna@example.org', ['DKI'])]); $this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($quiet), $this->row($due)]); $this->mailer ->expects($this->once()) ->method('createAndSendEmail') ->willReturnCallback(function (array $context, array $options) use ($due, $quiet): void { $this->assertSame('anna@example.org', $options['to']); $this->assertSame(Mailer::MAILJET_TRANSPORT, $options['transport']); $this->assertSame([$quiet, $due], array_column($context['travels'], 'destination')); }) ; $this->assertSame('Sent feedback reminders to 1 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY))); } /** * The questionnaire is only owed for travels ended since it went live (2026-11-11 here), and * a draft is told apart from one never started. */ public function testEachTravelSaysWhatIsStillOpen(): void { $beforeGoLive = $this->travel(14); // ended 2026-11-06 $draft = $this->travel(7); // ended 2026-11-13 $untouched = $this->travel(3); // ended 2026-11-17 $submitted = $this->travel(1); // ended 2026-11-19 $this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('anna@example.org', ['DKI'])]); $this->destinationRepository->method('findPendingForHouseManager')->willReturn([ $this->row($beforeGoLive, null, 2), $this->row($draft, 'draft', 0), $this->row($untouched, null, 1), $this->row($submitted, 'submitted', 3), ]); $travels = null; $this->mailer ->method('createAndSendEmail') ->willReturnCallback(function (array $context) use (&$travels): void { $travels = $context['travels']; }) ; $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY)); $this->assertSame( [[null, 2], ['draft', 0], ['open', 1], [null, 3]], array_map(fn (array $travel) => [$travel['questionnaire'], $travel['openRatings']], $travels) ); } /** * @param list $hotelCodes */ private function houseManager(string $email, array $hotelCodes): User { return (new User()) ->setEmail($email) ->setRoles(['ROLE_HOUSE_MANAGER']) ->setHotelCodes($hotelCodes) ->setTeamer(new Teamer()) ; } /** * @return array{0: Destination, questionnaireStatus: ?string, placements: int, openFeedbacks: int} */ private function row(Destination $destination, ?string $questionnaireStatus = null, int $openFeedbacks = 1): array { return [$destination, 'questionnaireStatus' => $questionnaireStatus, 'placements' => 2, 'openFeedbacks' => $openFeedbacks]; } private function travel(int $endedNightsAgo): Destination { $dateTo = (new \DateTimeImmutable(self::TODAY))->modify(sprintf('-%d days', $endedNightsAgo)); return (new Destination())->setDateFrom($dateTo->modify('-7 days'))->setDateTo($dateTo); } }