Skip to content

[HttpFoundation] BinaryFileResponse untestable? #10608

Closed
@anlutro

Description

@anlutro

BinaryFileResponse calls $file = new File((string) $file); on the first parameter of its constructor, which means that it can't easily be mocked. In a web test using the BrowserKit client, you have to provide the path to a file that actually exists for it to not throw an exception. This seems less ideal for a controller action that, for example, writes a file to the disk before letting the user download it. In some cases you will want to mock away that file system read/write operation.

I had a quick search on google and looked through the issues but couldn't find anything about this. Am I missing something here or is this a problem?

https://github.com/symfony/symfony/blob/v2.4.4/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php#L84
https://github.com/symfony/symfony/blob/v2.4.4/src/Symfony/Component/HttpFoundation/File/File.php#L40-L42

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions