google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 292 forks source link

Improve the test coverage for the `fpm-server-requirement-status` endpoint. #9708

Open techanvil opened 6 days ago

techanvil commented 6 days ago

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 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.

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:


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