now = new DateTimeImmutable( '2026-05-06T12:00:00', new DateTimeZone('UTC'), ); $this->commentRepo = new FakeCommentRepository; $this->useCase = new ListCommentsForPost($this->commentRepo); } private function seedComment(int $postId, string $body, string $offset): void { $this->commentRepo->create(new CreateCommentDto( postId: $postId, userId: 1, body: $body, createdAt: $this->now->modify($offset), )); } public function test_zero_post_id_throws_bad_request(): void { $this->expectException(BadRequestException::class); $this->useCase->execute(new ListCommentsForPostRequest( postId: 0, )); } public function test_returns_empty_list_when_no_comments(): void { $result = $this->useCase->execute(new ListCommentsForPostRequest( postId: 1, )); $this->assertSame([], $result); } public function test_returns_only_comments_for_given_post(): void { $this->seedComment(1, 'first', '+0 seconds'); $this->seedComment(2, 'other-post', '+0 seconds'); $this->seedComment(1, 'second', '+1 minute'); $result = $this->useCase->execute(new ListCommentsForPostRequest( postId: 1, )); $this->assertCount(2, $result); $this->assertSame('first', $result[0]->getBody()); $this->assertSame('second', $result[1]->getBody()); } }