PHPUnit set up test for file generation

Viewed 26

Following this question, I struggle to find the correct approach to create tests for a situation like this:

  1. different entry points in the application lead to generate some kind of PDF file (for sake of example, one could be /pdf/report and the other /pdf/details);

  2. each entry point calls a specific function in the PDFController, where it gathers the data to be placed in the PDF file (let's call the functions report and details);

  3. both functions, internally, call the same PDFService class (specifically, a function outputPDF($pdf_data) to generate the file to be sent back to the client.

    Inside this function there's the call mentioned in the other question, in particular the line $pdf->getMpdf()->Output($pdf_data['filename'], 'D');

The question is: how do I set up a feature test to check the /pdf/report and /pdf/details entry points?

As answered in the other question, I should change the 'D' format with 'S' in order to avoid the header to be sent beforehand, but that would change the actual behaviour of the software, where I want those PDF files to be downloaded.

Even passing the "output format" as a parameter to the outputPDF function (function outputPDF($pdf_data, $output_format)) sounds wrong, given it's just for the testing phase.

I think I'm missing something, here...

0 Answers
Related