Search code examples
unit-testinglaravellaravel-4phpunitmockery

Laravel Response::download() test


I have the following code in one of my routes:

return Response::download('cv.pdf');

Any idea how to test this? I've tried to use shouldReceive() but that doesn't seem to work ('shouldReceive() undefined function....').


Solution

  • EDIT: As pointed by @DavidBarker in his comment to the OP question

    The Illuminate\Support\Facades\Response class doesn't actually extend Illuminate\Support\Facades\Facade so doesnt have the shouldRecieve() method. You need to test the response of this route after calling it in a test.


    So if you want to test your download functionality, you can try checking the response for errors with:

    $this->assertTrue(preg_match('/(error|notice)/i', $response) === false);