createUser(['ROLE_DOCTOR']); $doctor = new Doctor($owner, 'دکتر تست'); $this->em->persist($doctor); $past = time() - 3600; $appointments = []; for ($i = 0; $i < 5; $i++) { $patient = $this->createUser(['ROLE_USER']); // distinct past slots — one live booking per (doctor, slot) $slotStart = $past - $i * 1000; $appt = $this->newAppointment($doctor, $patient, $slotStart, $slotStart + 900); // مثل مسیر واقعیِ رزرو آنلاین: نگه‌داشتِ موقت تا پرداخت درگاه. $appt->markPendingWithTtl(-1); $this->em->persist($appt); $payment = new Payment($patient, 100_000, 'mellat', 'appointment'); $payment->setAppointment($appt); $this->stampTenant($payment); $this->em->persist($payment); $appointments[] = [$appt, $payment]; } $this->em->flush(); $service = static::getContainer()->get(AppointmentExpiryService::class); $count = $service->expireStale(); // At least our 5 — db_test is shared and may hold other stale pendings // from earlier tests/runs; the per-row checks below verify our own 5. $this->assertGreaterThanOrEqual(5, $count); $this->em->clear(); foreach ($appointments as [$appt, $payment]) { $freshAppt = $this->em->getRepository(Appointment::class)->find($appt->getId()); $freshPay = $this->em->getRepository(Payment::class)->find($payment->getId()); $this->assertSame(Appointment::STATUS_EXPIRED, $freshAppt->getStatus()); $this->assertSame(Payment::STATUS_CANCELED, $freshPay->getStatus()); } } /** * نوبت «ثبت‌شده»ی پنل TTL ندارد؛ گذشتنِ ساعتِ نوبت نباید خودبه‌خود منقضی‌اش کند — * قطعی/لغو کردنش تصمیم اپراتور است. */ public function testPanelRegisteredPendingSurvivesExpiry(): void { $owner = $this->createUser(['ROLE_DOCTOR']); $doctor = new Doctor($owner, 'دکتر پنل'); $this->em->persist($doctor); $slotStart = time() - 7200; $appt = $this->newAppointment($doctor, $this->createUser(['ROLE_USER']), $slotStart, $slotStart + 900); $this->em->persist($appt); $this->em->flush(); static::getContainer()->get(AppointmentExpiryService::class)->expireStale(); $this->em->clear(); $fresh = $this->em->getRepository(Appointment::class)->find($appt->getId()); $this->assertSame(Appointment::STATUS_PENDING, $fresh->getStatus()); } }