Beginner in tests, I search the way to test my function which consists to check existence of my file and download it. At each test, I receive this error :
Error: Call to undefined method AppBundle\Controller\DownloadUserGuideController::setParameter()
My test :
public function testDownloadAction()
{
$DownloadUserGuideController = new DownloadUserGuideController();
$DownloadUserGuideController->setParameter('path_to_file','%kernel.root_dir%/data/User_Guide.pdf');
$result_response = $DownloadUserGuideController->downloadAction();
$this->assertSame(Response::HTTP_OK, $result_response->getStatusCode());
}
My function:
public function downloadAction()
{
$filePath = $this->getParameter('path_to_file');
if (!file_exists($filePath)) {
throw $this->createNotFoundException();
}
$response = new BinaryFileResponse($filePath);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
return $response;
}
Aucun commentaire:
Enregistrer un commentaire