If you use
wp_remote_request() or other wrappers for
WP_Http methods in your code, this makes it difficult to test, especially if the remote server may not be reachable from your testing environment. That’s why I created the
WP_HTTP_UnitTestCase to solve this by letting you mock the remote responses.
The usage details are there in the repository’s readme file.
It lets you mock the remote responses coming from the server, and also captures the data that was sent to the remote server so you can check that the correct requests are made.
As I continue to write unit tests for WordPress plugins I create, I think I’ll find this helper useful. I hope you might as well.
I tried using your script, but it seems to always return a WP_Error. I grok the code, but maybe I’m missing something. Do you have a use case you could provide either here or on github?
I am interested in what you’ve got going here though!
I don’t have an example right at hand, but if you send me a sample of what you’ve got I’ll be happy to help you debug it.