If you unit test your WordPress projects with PHPUnit, sooner or later you’ll want to test some code that interacts with the filesystem. If you are interacting with the filesystem properly, you’ll be using the
A few months ago I found myself needing to test some code that created a file using the WordPress filesystem API. I searched for a good solution, and found the information about mocking the filesystem on the PHPUnit website. But after tinkering with vfsStream, I decided it would be easier to build a simple filesystem mocker myself than to integrate vfsStream with the WP Filesystem API. So I did.
The result is the WP Filesystem Mock.
[It] Provides a class that can be used as a mock filesystem, and also a shim for the WordPress filesystem API that uses it. This is useful in unit tests that include simple filesystem operations.
It looks handy! Fyi we seem to have duplicated effort: we opened a WordPress track ticket to get a similar mock file system into WordPress core here: https://core.trac.wordpress.org/ticket/29544#comment:12
I’m suspect your implementation is probably better; ht what do you think about getting some sort of mock file system into wp core?
Thanks for the head’s up, Mike. I’ve left a comment on that ticket.