How do I mock HTTP requests for PHPUnit?
-
06-11-2019 - |
Question
I'm writing a plugin that makes requests to the Facebook graph API. As I don't want my unit tests to actually make these requests, how would I overcome this? My method calls both wp_remote_get
and wp_remote_post
. Searching there does seem to be a way to mock functions using runkit
, here
I want to avoid having contributers requiring too many dependencies so would like to avoid the above method. Is there any other options? My class extends the WP_UnitTestCase
so I'm hoping maybe there's something from the wp unit-tests that I could use?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange