The initial implementation of the test coverage for the fpm-server-requirement-status (see https://github.com/google/site-kit-wp/issues/9632) involved mocking the is_endpoint_healthy() protected method of the REST_First_Party_Mode_Controller, due to difficulty testing the code contained within the method.
Notably, although it's possible to mock file_get_contents(), it doesn't appear possible to mock the $http_response_header that gets set locally in the file_get_contents() caller's scope with off the shelf tooling.
We should improve the test coverage to ensure the code contained in is_endpoint_healthy() is covered. Possible angles include:
Refactoring REST_First_Party_Mode_Controller so we pass in say a Guzzle client instance, or our own wrapper to file_get_contents(), and use that rather than calling file_get_contents() directly, allowing us to pass in a mock client during testing and avoid mocking is_endpoint_healthy().
Adding E2E test coverage for the endpoint. This comes with its own challenges, notably mocking the health check to https://g-1234.fps.goog/mpath/healthy to avoid calling the real Google service from our E2E tests. It looks possible, but would involve some structural changes to our E2E test environment; this was explored during the implementation of 9632, see https://github.com/google/site-kit-wp/pull/9707. A more practical approach requiring less structural changes would be to provide filters for the health check URLs so we could override them during testing. However, the REST_First_Party_Mode_Controller described above is probably the best way to proceed here.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Feature Description
The initial implementation of the test coverage for the
fpm-server-requirement-status
(see https://github.com/google/site-kit-wp/issues/9632) involved mocking theis_endpoint_healthy()
protected method of theREST_First_Party_Mode_Controller
, due to difficulty testing the code contained within the method.Notably, although it's possible to mock
file_get_contents()
, it doesn't appear possible to mock the$http_response_header
that gets set locally in thefile_get_contents()
caller's scope with off the shelf tooling.https://github.com/google/site-kit-wp/blob/54f900c534c135682d44e4dfa8834e3891d91ff2/tests/phpunit/integration/Core/Tags/First_Party_Mode/REST_First_Party_Mode_ControllerTest.php#L235-L241
We should improve the test coverage to ensure the code contained in
is_endpoint_healthy()
is covered. Possible angles include:REST_First_Party_Mode_Controller
so we pass in say a Guzzle client instance, or our own wrapper tofile_get_contents()
, and use that rather than callingfile_get_contents()
directly, allowing us to pass in a mock client during testing and avoid mockingis_endpoint_healthy()
.https://g-1234.fps.goog/mpath/healthy
to avoid calling the real Google service from our E2E tests. It looks possible, but would involve some structural changes to our E2E test environment; this was explored during the implementation of 9632, see https://github.com/google/site-kit-wp/pull/9707. A more practical approach requiring less structural changes would be to provide filters for the health check URLs so we could override them during testing. However, theREST_First_Party_Mode_Controller
described above is probably the best way to proceed here.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
Test Coverage
QA Brief
Changelog entry