You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to mock google API calls via the recommended way in Guzzle and I could'nt understand why it would not work until I stumbled upon this part of the code:
And that's when I realized that if you have a custom stack handler which is the case when mocking, then the stack handler is not shared at all with the auth middleware stack handler.
As of today, to make it work I overrode the GoogleClient::getAuthHandler method to return a custom GuzzleAuthHandler which is basically a copy of the Guzzle6AuthHandler with one line updated in the createAuthHttp method:
This seems like a fine addition to me. The only reason this exists is because we want to ensure http_errors is set to true for auth calls. So if there's a better way to do that in Guzzle, we could do that also. Something like this might work:
Hello,
I have been trying to mock google API calls via the recommended way in Guzzle and I could'nt understand why it would not work until I stumbled upon this part of the code:
https://github.com/googleapis/google-api-php-client/blob/main/src/AuthHandler/Guzzle6AuthHandler.php#L106
And that's when I realized that if you have a custom stack handler which is the case when mocking, then the stack handler is not shared at all with the auth middleware stack handler.
As of today, to make it work I overrode the GoogleClient::getAuthHandler method to return a custom GuzzleAuthHandler which is basically a copy of the Guzzle6AuthHandler with one line updated in the createAuthHttp method:
That works but that's a lot of code which is (let's be honest) not that clean 😅
Is there any alternatives ? What would you think about adding this line during the http client creation ?
NB: My problematic concerns mocking but I guess that would also be true if you depend on another specific handler.
The text was updated successfully, but these errors were encountered: