serializer = self::getContainer()->get(SerializerInterface::class); } public function testDeleteComment(): void { $ticket = new Ticket(); $comment = new Comment('content', $ticket); $controller = $this->buildController(willFlush: true, isGranted: true, comment: $comment); $response = $controller->deleteComment($comment); self::assertEquals(200, $response->getStatusCode()); } public function testRestoreComment(): void { $ticket = new Ticket(); $comment = new Comment('content', $ticket); $controller = $this->buildController(willFlush: true, isGranted: true, comment: $comment); $response = $controller->restoreComment($comment); self::assertEquals(200, $response->getStatusCode()); } public function testDeleteCommentWithoutAuthorization(): void { $ticket = new Ticket(); $comment = new Comment('content', $ticket); $controller = $this->buildController(willFlush: false, isGranted: false, comment: $comment); $this->expectException(AccessDeniedHttpException::class); $this->expectExceptionMessage('You are not allowed to edit this comment.'); $controller->deleteComment($comment); } public function testRestoreCommentWithoutAuthorization(): void { $ticket = new Ticket(); $comment = new Comment('content', $ticket); $controller = $this->buildController(willFlush: false, isGranted: false, comment: $comment); $this->expectException(AccessDeniedHttpException::class); $this->expectExceptionMessage('You are not allowed to edit this comment.'); $controller->restoreComment($comment); } private function buildController(bool $willFlush, bool $isGranted, Comment $comment): UpdateCommentDeletedStatusController { $security = $this->prophesize(Security::class); $security->isGranted(CommentVoter::EDIT, $comment)->willReturn($isGranted); $entityManager = $this->prophesize(EntityManagerInterface::class); if ($willFlush) { $entityManager->flush()->shouldBeCalled(); } $commandHandler = $this->prophesize(UpdateCommentDeletedStatusCommandHandlerInterface::class); if ($isGranted && $willFlush) { $commandHandler->handle($comment, Argument::any())->shouldBeCalled(); } return new UpdateCommentDeletedStatusController( $security->reveal(), $this->serializer, $commandHandler->reveal(), $entityManager->reveal(), ); } }