unit testing - How can I write tests for file upload in PHP? -
I am using simplicity to write my PHP tests. I am writing a file upload plugin and wondering how I can test it.
I would like to check that the file has been uploaded properly, in the correct folder, when required, the error is returned properly, etc.
How do I simulate a file upload (via $ $ FILES variable)? Are there any issues I should be aware of?
I have found an alternate solution, I used the $ _ FILES
Along with the array, dummy test files are created in the tmp /
folder (folder is irrelevant, but I have tried to stick with default).
The problem was that is_uploaded_file
and move_uploaded_file
could not work with these badme objects because they were actually POST
. The first thing was that I had to wrap those tasks in my own moveUploadedFile
and isUploadedFile
in my plug-in so that I could duplicate them and change their return value.
The last thing that enhances the class while doing the test and instead of using moveUploadedFile
to move move_uploaded_file
and isUploadedFile
To overwrite rename
to use is_uploaded_file
instead of file_exists
.
Comments
Post a Comment