createUser(['ROLE_DOCTOR']); $doctor = new Doctor($owner, 'دکتر دسته‌بندی'); $this->em->persist($doctor); $this->em->flush(); $section = new ServiceSection('doctor', $doctor->getId(), 'لیزر'); $item = new ServiceItem($section, 'لیزر دست'); $item->setPriceRials(5_000_000); $this->em->persist($section); $this->em->persist($item); $this->em->flush(); return [$owner, $item]; } private function category(User $user, string $name): string { $body = $this->authJson('POST', '/api/v1/service-category', $user, ['name' => $name]); self::assertSame(201, $this->responseCode(), json_encode($body, JSON_UNESCAPED_UNICODE)); return $body['data']['uuid']; } // ── ✅ موفق ────────────────────────────────────────────────────────────── public function testAServiceTakesAGlobalCategory(): void { [$owner, $item] = $this->doctorWithItem(); $hand = $this->category($owner, 'دست'); $body = $this->authJson('PATCH', '/api/v1/service-item/' . $item->getUuid(), $owner, [ 'catalog_category_uuid' => $hand, ]); self::assertSame(200, $this->responseCode(), json_encode($body, JSON_UNESCAPED_UNICODE)); self::assertSame($hand, $body['data']['catalog_category_uuid']); } public function testNullClearsTheCategory(): void { [$owner, $item] = $this->doctorWithItem(); $hand = $this->category($owner, 'دست'); $this->authJson('PATCH', '/api/v1/service-item/' . $item->getUuid(), $owner, ['catalog_category_uuid' => $hand]); $body = $this->authJson('PATCH', '/api/v1/service-item/' . $item->getUuid(), $owner, ['catalog_category_uuid' => null]); self::assertSame(200, $this->responseCode()); self::assertNull($body['data']['catalog_category_uuid']); } // ── ⚠️ مرزی ───────────────────────────────────────────────────────────── public function testNotSendingTheFieldLeavesTheCategoryAlone(): void { [$owner, $item] = $this->doctorWithItem(); $hand = $this->category($owner, 'دست'); $this->authJson('PATCH', '/api/v1/service-item/' . $item->getUuid(), $owner, ['catalog_category_uuid' => $hand]); // فیلد در بدنه نیست: ویرایش نام نباید دسته را پاک کند. $body = $this->authJson('PATCH', '/api/v1/service-item/' . $item->getUuid(), $owner, ['name' => 'لیزر دست کامل']); self::assertSame($hand, $body['data']['catalog_category_uuid']); } // ── ❌ خطا ─────────────────────────────────────────────────────────────── public function testACategoryFromAnotherEnvironmentIsRefused(): void { [$owner, $item] = $this->doctorWithItem(); [$stranger] = $this->doctorWithItem(); $foreign = $this->category($stranger, 'دستهٔ پزشک دیگر'); $this->authJson('PATCH', '/api/v1/service-item/' . $item->getUuid(), $owner, [ 'catalog_category_uuid' => $foreign, ]); self::assertSame(422, $this->responseCode()); } }