entityManager = self::getContainer()->get(EntityManagerInterface::class); $this->repository = $this->entityManager->getRepository(Disposition::class); $this->entityManager->getConnection()->beginTransaction(); $this->teamer = (new Teamer())->setFirstName('Kim')->setLastName('Muster')->setGender('d'); $this->entityManager->persist($this->teamer); } protected function tearDown(): void { $this->entityManager->getConnection()->rollBack(); parent::tearDown(); } public function testAnEscortWithoutAResponseIsPending(): void { $disposition = $this->escort(); $this->assertSame([['disposition' => $disposition, 'draft' => false]], $this->pending()); } public function testADraftIsStillPendingAndSaysSo(): void { $disposition = $this->escort(); $this->respond($disposition, submit: false); $this->assertSame([['disposition' => $disposition, 'draft' => true]], $this->pending()); } public function testASubmittedQuestionnaireIsNoLongerPending(): void { $this->respond($this->escort(), submit: true); $this->assertSame([], $this->pending()); } /** * The questionnaire key belongs in the JOIN condition: in the WHERE clause, a submitted * response to some other questionnaire would hide this one. */ public function testAResponseToAnotherQuestionnaireDoesNotCount(): void { $disposition = $this->escort(); $this->respond($disposition, submit: true, questionnaire: 'other'); $this->assertSame([['disposition' => $disposition, 'draft' => false]], $this->pending()); } public function testAPlacementWithoutBusEscortIsPendingToo(): void { $disposition = $this->escort(); $disposition->getAssignment()->setPickup(0); $this->assertSame([['disposition' => $disposition, 'draft' => false]], $this->pending()); } public function testAnAssignmentEndingTodayIsPending(): void { $this->escort(dateTo: 'today'); $this->assertCount(1, $this->pending()); } /** * @param \Closure(Disposition): mixed $change */ #[\PHPUnit\Framework\Attributes\DataProvider('notPending')] public function testIsNotPending(\Closure $change): void { $change($this->escort()); $this->entityManager->flush(); $this->assertSame([], $this->pending()); } /** * @return array */ public static function notPending(): array { return [ 'not over yet' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('tomorrow'))], 'ended before go-live' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('2025-12-31'))], 'skip formalities' => [static fn (Disposition $d) => $d->getAssignment()->setSkipFormalities(true)], 'called off' => [static fn (Disposition $d) => $d->setStatus(Disposition::STATUS_CALLED_OFF)], 'assignment called off' => [static fn (Disposition $d) => $d->getAssignment()->setStatus(Assignment::STATUS_CALLED_OFF)], ]; } public function testAnotherTeamersEscortIsNotListed(): void { $other = (new Teamer())->setFirstName('Alex')->setLastName('Beispiel')->setGender('d'); $this->entityManager->persist($other); $this->escort(teamer: $other); $this->assertSame([], $this->pending()); } /** * @return list */ private function pending(): array { $this->entityManager->flush(); return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, new \DateTimeImmutable(self::GO_LIVE)); } }