em->getRepository(SiteConfig::class)->findOneBy(['configKey' => 'payment_test_mode']); if ($cfg === null) { $this->em->persist(new SiteConfig('payment_test_mode', '1')); } else { $cfg->setValue('1'); } $this->em->flush(); } /** @return array{0: Payment, 1: Appointment} */ private function pendingPaidBooking(?callable $withClinic = null): array { $doctor = new Doctor($this->createUser(['ROLE_DOCTOR']), 'دکتر پرداخت'); $this->em->persist($doctor); $this->em->flush(); $appointment = new Appointment($doctor, $this->createUser(['ROLE_USER']), 1_790_200_000, 1_790_201_800); if ($withClinic !== null) { $appointment->setClinic($withClinic($doctor)); } $this->em->persist($appointment); $payment = new Payment($appointment->getUser(), 50_000, 'mock', Payment::TYPE_APPOINTMENT); $payment->setAppointment($appointment); $this->em->persist($payment); $this->em->flush(); return [$payment, $appointment]; } private function fireCallback(Payment $payment): void { $this->client->request('POST', '/api/v1/payment/callback/mock?' . http_build_query([ 'order_id' => $payment->getOrderId(), 'mock' => '1', 'ResCode' => '0', 'mock_amount' => '50000', ])); } public function testPaidPersonalBookingIsConfirmedAndFiled(): void { $this->enableTestMode(); [$payment, $appointment] = $this->pendingPaidBooking(); $this->fireCallback($payment); $this->em->clear(); $reloaded = $this->em->getRepository(Appointment::class)->find($appointment->getId()); self::assertSame(Appointment::STATUS_CONFIRMED, $reloaded->getStatus()); $sessions = $this->em->getRepository(PatientSession::class)->findBy(['appointment' => $reloaded]); self::assertCount(1, $sessions, 'پرداخت آنلاین هم باید پرونده بسازد'); $record = $sessions[0]->getRecord(); self::assertSame('doctor', $record->getEntityType()); } public function testPaidClinicBookingIsFiledUnderTheClinic(): void { $this->enableTestMode(); [$payment, $appointment] = $this->pendingPaidBooking(function (Doctor $doctor): Clinic { $clinic = new Clinic($this->createUser(['ROLE_CLINIC'])); $clinic->setName('کلینیک پرداخت'); $clinic->getDoctors()->add($doctor); $this->em->persist($clinic); $this->em->flush(); return $clinic; }); $this->fireCallback($payment); $this->em->clear(); $reloaded = $this->em->getRepository(Appointment::class)->find($appointment->getId()); $records = $this->em->getRepository(PatientRecord::class)->findBy(['user' => $reloaded->getUser()]); self::assertCount(1, $records, 'یک نوبت، یک پرونده — نه یکی برای پزشک و یکی برای کلینیک'); self::assertSame('clinic', $records[0]->getEntityType()); } }