Phongthorn
03/18/2022, 5:14 AMuse GuzzleHttp\Client;
Class InternalClient extends Client
{
// ....
}
Class UserApi
{
public function __construct(private InterClient $client)
{
}
}
In this case, I should mock InternalClient or UserApi?
Now, I got this error
Server error: `GET <http://localhost:7200/interactions/verification>` resulted in a `500 Internal Server Error` response:
Actual interactions do not match expected interactions for mock MockService.
Incorrect requests:
GET /v1/sso-user/id (truncated...)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Phongthorn
03/18/2022, 6:14 AMbase_uri
, I the API Client not use this to set default endpoint. The endpoint will be placed in UserAPi like this
Class UserApi
{
public function __construct(private InterClient $client)
{
$this->client->setEndpoint('<http://localhost/v1/user>');
}
}
But in the example of Pact PHP see only a way to mock with base_uri.
$service = new HttpClientService($config->getBaseUri()); // Pass in the URL to the Mock Server.
$result = $service->getHelloString('Bob'); // Make the real API request against the Mock Server.
Because our API Client does not use base_uri. It makes a request by itself like this
public function request($method, $uri = '', array $options = []) : ResponseInterface
{
$uri = $this->baseUrl . $uri;
try {
$response = $this->makeRequest($method, $uri, $options);
....
}
This is an override Client method. Now I try to create a new Class using the default Client class (GuzzleHttp) instead of the custom Client API class. See it work properly. Need to try more . . .Matt (pactflow.io / pact-js / pact-go)
Phongthorn
03/18/2022, 6:25 AM