-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
setResponseOfPath not working with query parameters #6
Comments
That is the expected correct behaviour. You are defining the endpoint, not including the GET parameters. Your API call can append whatever GET parameters it wants and then you can verify you received them as follows: <?php
use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\RequestInfo;
use donatj\MockWebServer\Response;
require 'vendor/autoload.php';
$server = new MockWebServer();
$server->start();
$url = $server->setResponseOfPath("/api/endpoint", new Response('abc'));
$content = file_get_contents($url . '?with=parameter');
print_r($server->getLastRequest()[RequestInfo::JSON_KEY_GET]); which returns
|
ok, will have to use something else -- we have APIs with parameters and in our integration tests, multiple calls to the same API can be made. |
Do you need to test multiple API calls at a time? If you're testing a single API call at a time, you can easily change the response of an endpoint. Otherwise you can queue up responses, see: https://github.com/donatj/mock-webserver#multiple-responses-to-the-same-endpoint |
We have APIs we test internally that vary on GET parameters, as well but we are only testing a single call at a time, so we can easily do as follows: <?php
use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\Response;
require 'vendor/autoload.php';
$server = new MockWebServer();
$server->start();
// Psuedo API object
$api = new Api();
$url = $server->setResponseOfPath("/api/endpoint", new Response('first response'));
$api->makeCallOne();
// do validaitons
$url = $server->setResponseOfPath("/api/endpoint", new Response('more different response'));
$api->makeCallTwo();
// do validations We use PHPUnit to run are tests and simply set the body for the endpoint at the top of each test case. |
I am currently laying the groundwork to support varying by query string, and hope to have a solution in the next couple days. Hold tight. |
Hi @donatj - I recently started using |
This works:
While this does not:
Instead of returning def, it returns the information about the request.
The text was updated successfully, but these errors were encountered: