-
Notifications
You must be signed in to change notification settings - Fork 338
Update to Guzzle 6+ #1146
Copy link
Copy link
Closed
Labels
Exp: SPP1Medium priorityMedium priorityPHPQA: EngRequires specialized QA by an engineerRequires specialized QA by an engineerType: InfrastructureEngineering infrastructure & toolingEngineering infrastructure & tooling
Description
Feature Description
As mentioned a few times, most recently again in #223.
Perhaps it could just be bumped? google/apiclient supports it, so there shouldn't be a conflict in that regard.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
guzzlehttp/guzzleshould be upgraded to the latest v6 version (but not v7)- All existing Guzzle client customizations must continue to work (see
Client_Factory::create_client)
- All existing Guzzle client customizations must continue to work (see
Implementation Brief
- A working branch has been started in https://github.com/google/site-kit-wp/tree/enhance/1146-guzzle6 with a draft PR in Upgrade Guzzle to v6 #6581
- Most of the exploration to understand what is needed here should be done, the main part remaining is refactoring the use of
FakeHttpClientwith Guzzle'sMockHandler- The reason for this is because staring with Guzzle v6, the
Clientis designed to be immutable, so in order to make changes, a new instance must be set/returned. Because of this, an alternate client instance is lost as soon as such a modification is needed, and since this happens within the Google API client as part of every request when providing theaccess_token, it's no longer a viable strategy. - The
MockHandlerfor overriding requests in tests will persist acrossClientinstances via thehandlerrequest option.
- The reason for this is because staring with Guzzle v6, the
- Replace the use of
FakeHttpClientwith aMockHandlervia the Guzzle client'shandlerconfiguration. See https://docs.guzzlephp.org/en/6.5/testing.html for details- This is not a 1-1 replacement as a
MockHandlerserves requests in order from a given queue whereasFakeHttpClienthas full control over the response returned so we may want to look into extending theMockHandlerto allow for conditional responses rather than a simple queue (a quick search yielded a package that provides something similar so it should at least be possible, or we can maybe even just use this one) - The flow to mock one or more responses generally looks like this
- Get the Guzzle config from the Google API's http client (
Google_Client->getHttpClient()->getConfig()) - Modify the config to include the configured
handler - Create a new
Clientusing the new/modified config array - Set the new
Clientback in the Google API client (Google_Client->setHttpClient(newClientInstance))
- Get the Guzzle config from the Google API's http client (
- This is not a 1-1 replacement as a
- Remove
FakeHttpClient
QA Brief
- This issue changes the main underlying library used for making API requests with Google APIs, including oAuth token requests
- Setup flows and dashboard views should be thoroughly checked for potential regressions
- We should test that things work on both oldest (5.6) and latest (8.0/8.1) supported versions of PHP, as well as PHP 7.4 (being the most common)
QA:Eng
- Ensure HTTP proxy functionality still works
- Ensure user-agent and other customizations to the client still work
Changelog entry
- Upgrade Guzzle, with
guzzlehttp/guzzleupdated to v6.5.8.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Exp: SPP1Medium priorityMedium priorityPHPQA: EngRequires specialized QA by an engineerRequires specialized QA by an engineerType: InfrastructureEngineering infrastructure & toolingEngineering infrastructure & tooling