I am busy coding a unit test for an AJAX file uploader. The beginning of my save function looks like this:
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
I’m trying to find a way to stuff data into the input stream so that $input is populated with appropriate test data.
I’ve tried writing to the output stream before reading, but it seems to output immediately to stdio. I’ve watched the console with Firebug while uploading a file to get clues on how to set the Request variables but I’ve hit a blank.
I’ve also tried this:
$inStream = fopen("php://input", "w");
$input = fopen("libs/inputfile.txt", "r");
stream_copy_to_stream($input, $inStream);
but $realSize always returns 0 – I’m assuming this is because the php://input stream is readonly
You can wrap
fopen("php://input", "r");into your custom class/method and then mock it with test class/method.