-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock HTTP requests #210
Comments
I like the idea of being able to easily mock HTTP requests in Behat tests. I think I recently needed something similar as well. |
I think there are undoubtedly places it could be used in WP-CLI itself but it hasn't been required thanks to predictable behaviour – e.g. wordpress.org is probably not returning HTTP 500s for In context of Obviously, I think it's a valuable function and should be included. And I guess I am using this issue as a litmus test for other PRs that I'll know not to open if the policy is to only add functions that are directly used by WP-CLI itself, e.g. the More broadly, providing more tools for testing plugins is only going to improve the WordPress ecosystem. Alternatively, I could publish a Composer package with this (and more functions) but the lack of visibility would be to the detriment of everyone who would potentially use this. I searched GitHub for plugins with Behat WP-CLI tests and found very few, I think there is some low hanging fruit like this that can help improve that. |
I wouldn't call it a policy or requirement to only add things that we need ourselves, but if we have more use cases that helps shaping and testing such a new feature. For example, there might be a need to easily disable all network requests to mimic a server being offline, or a way to simply respond with a specific HTTP status for some requests or all requests. Such scenarios could be helpful for both plugins and WP-CLI. |
Feature Request
Describe your use case and the problem you are facing
When writing my own CLI commands, they sometimes perform HTTP requests. E.g. I'm currently working with a software licence server, I want a CLI command to activate the licence, but I don't want to use a real licence server which would decrement the available licence activations and return different responses when the test is re-run.
Maybe WP CLI already has this utility, but I didn't see it.
Describe the solution you'd like
Filter
pre_http_request
by creating an mu-plugin for the test case which loads a PHP file containing the mocked response.Add this to GivenStepDefinitions.php
And a feature would look like:
This could be generalised to almost every filter, so maybe I missed it because I was looking for a http mock.
I need to write tests on that switch statement.
The text was updated successfully, but these errors were encountered: