createUser(['ROLE_DOCTOR']); $doctor = new Doctor($user, 'دکتر تماس'); $this->em->persist($doctor); $address = DoctorAddress::forDoctor($doctor) ->setName('مطب مرکزی') ->setAddress('یزد، خیابان کاشانی') ->setTelephone($phone); $this->em->persist($address); $this->em->flush(); // درخواستِ کرنل همین EM را می‌بیند و کالکشنِ آدرس‌های این نمونه از لحظهٔ // ساخت خالی مانده است؛ بدون clear، پاسخ آدرسی نشان نمی‌دهد. $this->em->clear(); return [ $this->em->getRepository(Doctor::class)->find($doctor->getId()), $this->em->getRepository(DoctorAddress::class)->find($address->getId()), $this->em->getRepository(\App\Auth\Entity\User::class)->find($user->getId()), ]; } public function testPublicDoctorResponseKeepsTheAddressButDropsThePhone(): void { [$doctor, , ] = $this->doctorWithAddress(); $this->client->request('GET', '/api/v1/doctor/' . $doctor->getUuid()); $this->assertSame(200, $this->responseCode()); $payload = json_decode($this->client->getResponse()->getContent(), true); $address = $payload['data']['data']['address'][0]; $this->assertSame('یزد، خیابان کاشانی', $address['address'], 'آدرس باید عمومی بماند'); $this->assertNull($address['telephone'], 'شمارهٔ مطب نباید عمومی باشد'); } public function testTheDoctorStillSeesTheirOwnPhone(): void { [$doctor, , $owner] = $this->doctorWithAddress(); $body = $this->authJson('GET', '/api/v1/doctor/' . $doctor->getUuid(), $owner); $this->assertSame('03536666666', $body['data']['data']['address'][0]['telephone']); } public function testThePatientSeesTheVenuePhoneOnTheirOwnAppointment(): void { [$doctor, $address, ] = $this->doctorWithAddress(); $patient = $this->createUser(['ROLE_USER']); $appointment = $this->newAppointment($doctor, $patient, time() + 3600, time() + 5400); $appointment->setAddressId((int) $address->getId()); $this->em->persist($appointment); $this->em->flush(); $body = $this->authJson('GET', '/api/v1/appointments/user', $patient); $row = $body['data']['data'][0]; $this->assertSame($appointment->getUuid(), $row['uuid']); $this->assertSame('یزد، خیابان کاشانی', $row['address']['address']); $this->assertSame('03536666666', $row['address']['telephone']); } /** * پیش از این نشانی نوبت «اولین آدرس پزشک» بود، پس بیمارِ شعبهٔ دوم نشانی و شمارهٔ * شعبهٔ اول را می‌دید — نه فقط ناقص، که نشانیِ اشتباه. */ public function testTheAppointmentShowsItsOwnVenueNotTheDoctorsFirstOne(): void { [$doctor, , ] = $this->doctorWithAddress('03511111111'); $second = DoctorAddress::forDoctor($doctor) ->setName('مطب دوم') ->setAddress('یزد، صفائیه') ->setTelephone('03522222222'); $this->em->persist($second); $this->em->flush(); $patient = $this->createUser(['ROLE_USER']); $appointment = $this->newAppointment($doctor, $patient, time() + 3600, time() + 5400); $appointment->setAddressId((int) $second->getId()); $this->em->persist($appointment); $this->em->flush(); $row = $this->authJson('GET', '/api/v1/appointments/user', $patient)['data']['data'][0]; $this->assertSame('یزد، صفائیه', $row['address']['address']); $this->assertSame('03522222222', $row['address']['telephone']); } }