createUser(['ROLE_DOCTOR']), 'دکتر تست'); $this->em->persist($doctor); $root = (new Comment($this->createUser(), $doctor, 'نظر ریشه'))->approve(); $this->em->persist($root); // two likes + one dislike → like_count 2, dislike_count 1 $this->em->persist(new Like($this->createUser(), $root, 1)); $this->em->persist(new Like($this->createUser(), $root, 1)); $this->em->persist(new Like($this->createUser(), $root, -1)); $reply = (new Comment($this->createUser(), $doctor, 'پاسخ تأییدشده', $root))->approve(); $this->em->persist($reply); // a pending reply must NOT appear $this->em->persist(new Comment($this->createUser(), $doctor, 'پاسخ در انتظار', $root)); $this->em->flush(); $this->em->clear(); $body = $this->jsonGet('/api/v1/comments/' . $doctor->getUuid()); $roots = $body['data']['data']; $this->assertCount(1, $roots); $r = $roots[0]; $this->assertSame('نظر ریشه', $r['comment']); $this->assertSame(2, $r['like_status']['like_count']); $this->assertSame(1, $r['like_status']['dislike_count']); $this->assertCount(1, $r['replies']); // only the approved reply $this->assertSame('پاسخ تأییدشده', $r['replies'][0]['comment']); } private function jsonGet(string $uri): array { $this->client->request('GET', $uri); return json_decode($this->client->getResponse()->getContent(), true) ?? []; } }