Changes between Version 1 and Version 2 of Ticket #26829, comment 3
- Timestamp:
- 01/15/2014 11:18:04 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #26829, comment 3
v1 v2 1 1 Hi Nacin, 2 2 3 I actually need some input on the best way to handle testing `extract_from_markers()` and `insert_with_markers()`. Since the code uses the functions `file()`, `fopen()`, etc., we would need to create files just for the unit tests, create temporary files programmatically within the tests, or rewrite the functions to use an object that we could mock. 4 3 5 I see that there's a directory for files required for certain unit tests, but I'm not sure where to put test htaccess files. Also, are the files in the /phpunit/data/ directory only to be used for read operations? If that's the case, I start to lean towards wanting to create a temp file with `tempname()`, but there is a possibility that `tempname()` won't work on some computers. 6 4 7 Is there a way we can replace the php filesystem calls with an object that can be mocked? I just found the `WP_Filesystem_Direct` class which has the function `get_contents_array()` which is just an abstraction for `file()`. The calls to `fopen`, `fwrite`, and `fclose` in the `insert_with_markers()` function could be removed by first making changes into a new array, imploding that array, and passing the resulting string into the `put_contents()` function. 8 5 9 So what route do you believe would be the best for WordPress and the Test Suite as a whole? I'm a fan of refactoring the functions to allow for mocks, but you know much more about this whole project than me and I'm willing to go a different route.