now = new DateTimeImmutable( '2026-05-06T12:00:00', new DateTimeZone('UTC') ); $this->postRepo = new FakePostRepository; $this->useCase = new GetPost($this->postRepo); } public function test_zero_id_throws_bad_request(): void { $this->expectException(BadRequestException::class); $this->useCase->execute(0); } public function test_negative_id_throws_bad_request(): void { $this->expectException(BadRequestException::class); $this->useCase->execute(-5); } public function test_unknown_id_returns_null(): void { $result = $this->useCase->execute(999); $this->assertNull($result); } public function test_existing_id_returns_post(): void { $created = $this->postRepo->create(new CreatePostDto( userId: 7, title: 'My Post', body: 'Some body content.', createdAt: $this->now, )); $result = $this->useCase->execute($created->getId()); $this->assertInstanceOf(Post::class, $result); $this->assertSame('My Post', $result->getTitle()); $this->assertSame(7, $result->getUserId()); } }