Call to a member function getParameter() on null into my PHPUnit Test

376
April 13, 2018, at 7:43 PM

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 a member function getParameter() on null

My test :

public function testDownloadAction()
{
    $DownloadUserGuideController = new DownloadUserGuideController();
    $DownloadUserGuideController->setParameter('%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;
}
public function setParameter($parameter)
{
    $this->parameter = $parameter;
    return $this;
}
Rent Charter Buses Company
READ ALSO
Php malware files remove from ubuntu [on hold]

Php malware files remove from ubuntu [on hold]

I have a web server(ubuntu OS) in AWS and many wordpress web sites are alive in there nowBut I got random php files ago a few days

143
Laravel / PHP - Convert plain links in text to nice links with page title

Laravel / PHP - Convert plain links in text to nice links with page title

I've searched a lot but couldn't really find any relevant discussionHere's the case at my hand -

161
Paypal showing error page while passing variables to sandbox environment

Paypal showing error page while passing variables to sandbox environment

I am trying to integrate paypal for one time donation save data to database and then mark paid/unpaid using Paypal IPN, I was working with below code yesterday, it was working fine and was redirecting me to sandbox page to pay and then come back

138