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
{{ message }}
Repository navigation
Defer mock Requests transport instantiation until http_request_options - #432
Updates src/Context/templates/mock-requests.php so it no longer probes interface_exists( '\WpOrg\Requests\Transport' ) or declares the transport class eagerly at file-require time (during WP-CLI's LoadRequiredCommand bootstrap step).
Why
When WP-CLI defers loading WordPress core's Requests library until Runner::load_wordpress(), requiring mock-requests.php eagerly during bootstrap would otherwise trigger bundled Requests v2 autoloading prematurely—breaking compatibility when WordPress <= 6.1 (Requests v1) is subsequently loaded.
Changes
Move the transport class instantiation inside the http_request_options hook callback using anonymous classes implementing \WpOrg\Requests\Transport (v2) or \Requests_Transport (v1).
Ensure WP_CLI\RequestsLibrary::register_autoloader() is called inside http_request_options before checking for the transport interface so the active Requests version is always registered first.
Remove the now-unnecessary Generic.Files.OneObjectStructurePerFile and Generic.Classes.DuplicateClassName PHPCS exclusions for src/Context/templates/*.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
No actionable comments were generated in the recent review.
Walkthrough
The mock Requests template now conditionally registers the Requests autoloader and assigns an anonymous v1 or v2 transport through the request-options hook. New subprocess tests cover template loading, autoloader registration, and transport selection.
Changes: Mock Requests transport
Layer / File(s)
Summary
Initialize the mock transport src/Context/templates/mock-requests.php, phpcs.xml.dist
The hook conditionally registers the Requests autoloader and assigns an anonymous transport that implements the available v1 or v2 interface. The PHPCS exclusions for the template directory were removed, and the related comment was updated.
Verify template loading and transport selection tests/tests/TestMockRequestsTemplate.php
Subprocess tests check that requiring the template does not trigger autoloading, and that invoking the hook registers the autoloader when available and returns a v1 or v2 transport.
The change defers mock Requests transport creation so bundled Requests v2 is not autoloaded too early during WP-CLI bootstrap. No merge-blocking issue was found, and new tests cover the lazy-loading and version-selection behavior.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: mock Requests transport creation is moved from file load time to the http_request_options hook. The raw summary and PR objectives both describe this deferral as the pr…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the main change: mock Requests transport creation is moved from file load time to the http_request_options hook. The raw summary and PR objectives both describe this deferral as the primary change, so the title matches the changeset.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Fix failing CI checks
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: d1363dac-2b29-473b-969c-96c18562f6e4
Commits
Reviewing files that changed from the base of the PR and between 791f3c1 and 9df02af.
Files selected for processing: 3
phpcs.xml.dist
src/Context/templates/mock-requests.php
tests/tests/TestMockRequestsTemplate.php
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updates
src/Context/templates/mock-requests.phpso it no longer probesinterface_exists( '\WpOrg\Requests\Transport' )or declares the transport class eagerly at file-require time (during WP-CLI'sLoadRequiredCommandbootstrap step).Why
When WP-CLI defers loading WordPress core's Requests library until
Runner::load_wordpress(), requiringmock-requests.phpeagerly during bootstrap would otherwise trigger bundled Requests v2 autoloading prematurely—breaking compatibility when WordPress <= 6.1 (Requests v1) is subsequently loaded.Changes
http_request_optionshook callback using anonymous classes implementing\WpOrg\Requests\Transport(v2) or\Requests_Transport(v1).WP_CLI\RequestsLibrary::register_autoloader()is called insidehttp_request_optionsbefore checking for the transport interface so the active Requests version is always registered first.Generic.Files.OneObjectStructurePerFileandGeneric.Classes.DuplicateClassNamePHPCS exclusions forsrc/Context/templates/*.