createUser(['ROLE_USER', 'ROLE_DOCTOR']); $doctor = new Doctor($doctorUser, 'دکتر عضو کلینیک'); $doctor->setMobileNumber($doctorUser->getMobileNumber()); $this->em->persist($doctor); $owner = $this->createUser(['ROLE_USER', 'ROLE_CLINIC']); $clinic = new Clinic($owner); $clinic->setName('کلینیک قیمت ویزیت'); $clinic->getDoctors()->add($doctor); $this->em->persist($clinic); $this->em->flush(); // محیطِ فعالِ مالک: خودِ کلینیک. همین است که فیلتر را روشن می‌کند. $this->em->persist(new UserActiveContext( $this->em->find(User::class, $owner->getId()), $clinic->getUuid(), 'clinic', )); $this->em->flush(); return [$owner, $doctor]; } private function save(User $owner, Doctor $doctor, int $rials): array { return $this->authJson('PUT', '/api/v1/insurance-pricing', $owner, [ 'doctor_uuid' => $doctor->getUuid(), 'free_visit_price_rials' => $rials, ]); } private function read(User $owner, Doctor $doctor): array { return $this->authJson('GET', '/api/v1/insurance-pricing?doctor_uuid=' . $doctor->getUuid(), $owner); } public function testTheSavedVisitPriceComesBack(): void { [$owner, $doctor] = $this->clinicOwnerWithMemberDoctor(); $this->save($owner, $doctor, 3_000_000); self::assertSame(200, $this->responseCode()); $body = $this->read($owner, $doctor); self::assertSame(3_000_000, $body['data']['free_visit_price_rials']); } public function testSavingTwiceUpdatesTheSameRowInsteadOfPilingUpNewOnes(): void { [$owner, $doctor] = $this->clinicOwnerWithMemberDoctor(); $this->save($owner, $doctor, 3_000_000); $this->save($owner, $doctor, 4_500_000); $rows = $this->em->getConnection()->fetchAllAssociative( 'SELECT patient_share_rials FROM entity_insurance_pricing WHERE entity_type = ? AND entity_id = ? AND insurance_id IS NULL', ['doctor', $doctor->getId()], ); self::assertCount(1, $rows, 'ذخیرهٔ دوباره نباید ردیف تازه بسازد'); self::assertSame(4_500_000, (int) $rows[0]['patient_share_rials']); self::assertSame(4_500_000, $this->read($owner, $doctor)['data']['free_visit_price_rials']); } }