You basically need to make your code more verified. Break it down so that you can test the simple act of uploading a file via HTTP separately from the rest of the code. The main use of move_uploaded_file is to add an extra security stop so that you cannot be tricked by moving any other file, move_uploaded_file just ensures that the file was loaded in the same request and then moved. You can simply move the file using rename . Thus, break the application to have one Request object that submits and encapsulates the current HTTP request, including forcing it to check downloaded files using is_uploaded_file . After that, you can use rename instead of move_uploaded_file . In your tests, you can then mock the Request object and check your other code.
You can also just make move_uploaded_file mockable, for example as follows:
class Foo { public function do() { ... $this->move_uploaded_file($from, $to); ... } protected function move_uploaded_file($from, $to) { return move_uploaded_file($from, $to); } }
In your tests, you can extend / mock a class and override Foo::move_uploaded_file always return true , for example.
source share