In this new post to his site Paul Jones makes a recommendation to those working with files and other resources: pass around the resources themselves (the streams) not filenames.
In testing the Aura.Http package, I have realized that it’s much more flexible, testing wise, to pass around file resources (a.k.a. handles, pointers, or streams) than it is to pass around file names. When you do that, you can use a php://memory stream instead of attempting to touch the file system. [...] This places control of the file creation in your hands directly, not under the control of the system under test.
He gives examples based on some testing of one of his own packages where he needed to swap out the resource being tested and mock out a file system call. It's a simple trick but could help reduce some complexity in your overall code in the right situations.