Refactor code structure for improved readability and maintainability

This commit is contained in:
hamed
2026-07-23 15:47:17 +03:30
parent a0a2eb1799
commit f00ed23f00
14 changed files with 1406 additions and 1351 deletions
+38
View File
@@ -11,6 +11,7 @@ use App\Patient\Entity\PatientRecord;
use App\Patient\Entity\PatientSession;
use App\Patient\Entity\SessionPayment;
use App\Tests\ApiTestCase;
use App\UserProfile\Entity\UserProfile;
/**
* GET /api/v1/my/billing/payments — flat, tenant-scoped list of recorded
@@ -161,6 +162,43 @@ class PatientPaymentsTest extends ApiTestCase
self::assertSame(40000, $onlyPartial['data'][0]['paid_rials']);
}
/** بیمارِ ساخته‌شده در نوبت‌دهی کد ملی را روی پروفایل دارد نه روی users. */
private function patientRecordWithProfileCode(Doctor $doctor, string $realName, string $nationalCode): PatientRecord
{
$patient = $this->createUser(['ROLE_USER']);
$this->setField($patient, 'realName', $realName);
// users.national_code خالی؛ کد ملی فقط روی پروفایل.
$profile = new UserProfile($patient);
$profile->setNationalCode($nationalCode);
$this->em->persist($profile);
$record = new PatientRecord('doctor', $doctor->getId(), $patient, 'doctor', $doctor->getId());
$this->em->persist($record);
$this->em->flush();
return $record;
}
public function testNationalCodeFromProfileSurfacesInListAndDetail(): void
{
[$owner, $doctor] = $this->doctor();
$nc = str_pad((string) random_int(0, 9_999_999_999), 10, '0', STR_PAD_LEFT);
$record = $this->patientRecordWithProfileCode($doctor, 'بیمار پروفایلی', $nc);
$this->invoice($doctor, $record, Invoice::STATUS_FINALIZED, 100000, 1000, null, 0, 100000);
// لیست
$list = $this->authJson('GET', '/api/v1/my/billing/payments', $owner);
self::assertSame($nc, $list['data'][0]['national_code']);
// فیلتر با کد ملیِ پروفایل
$filtered = $this->authJson('GET', '/api/v1/my/billing/payments?national_code=' . $nc, $owner);
self::assertSame(1, $filtered['meta']['totalRecords']);
// هدرِ صفحهٔ جزئیات
$detail = $this->authJson('GET', '/api/v1/my/billing/patients/' . $record->getUuid() . '/invoices', $owner);
self::assertSame($nc, $detail['data']['patient']['national_code']);
}
public function testEmptyWhenNoInvoices(): void
{
[$owner] = $this->doctor();