createUser(['ROLE_DOCTOR']); $doctor = new Doctor($owner, 'دکتر تست بخش'); $this->em->persist($doctor); // بخش به شناسهٔ پزشک نیاز دارد، پس پزشک باید پیش از ساختش flush شود. $this->em->flush(); $section = new ServiceSection('doctor', $doctor->getId(), 'بخش لیزر'); $this->em->persist($section); $item = new ServiceItem($section, 'لیزر توتال', 0); $item->setDurationMinutes(40)->setBookable(true); $this->em->persist($item); $this->em->flush(); return [$doctor, $section, $item]; } /** ✅ موفق — بخشِ ذخیره‌نشده از روی سرویس پر می‌شود. */ public function testSectionIsDerivedFromTheServiceItemWhenMissing(): void { [$doctor, $section, $item] = $this->doctorWithOneService(); $patient = $this->createUser(['ROLE_USER']); $start = strtotime('+5 days 10:00'); $appt = $this->newAppointment($doctor, $patient, $start, $start + 2400); $appt->replaceServiceItems([$item]); self::assertNull($appt->getServiceSection(), 'پیش‌فرضِ این سناریو: نوبت بخش ندارد'); $this->em->persist($appt); $this->em->flush(); $res = $this->authJson('GET', '/api/v1/appointment/' . $appt->getUuid(), $doctor->getUser()); self::assertSame(200, $this->responseCode()); $payload = $res['data']['data']; self::assertSame($section->getUuid(), $payload['service_section']['uuid']); self::assertSame('بخش لیزر', $payload['service_section']['name']); self::assertSame($item->getUuid(), $payload['service_item']['uuid']); } /** ⚠️ مرزی — نوبتِ بدون هیچ سرویسی چیزی برای استنتاج ندارد و `null` می‌ماند. */ public function testSectionStaysNullWhenTheAppointmentHasNoService(): void { [$doctor] = $this->doctorWithOneService(); $patient = $this->createUser(['ROLE_USER']); $start = strtotime('+6 days 10:00'); $appt = $this->newAppointment($doctor, $patient, $start, $start + 1800); $this->em->persist($appt); $this->em->flush(); $res = $this->authJson('GET', '/api/v1/appointment/' . $appt->getUuid(), $doctor->getUser()); self::assertSame(200, $this->responseCode()); self::assertNull($res['data']['data']['service_section']); } /** ❌ خطا — نوبتِ ناموجود همچنان ۴۰۴ است؛ fallback مسیر خطا را عوض نمی‌کند. */ public function testUnknownAppointmentStillReturns404(): void { [$doctor] = $this->doctorWithOneService(); $this->authJson('GET', '/api/v1/appointment/00000000-0000-0000-0000-000000000000', $doctor->getUser()); self::assertSame(404, $this->responseCode()); } }