Repository navigation
Closes #66: expose the requests HttpRequestTrait received - #67
Merged
remyperona merged 2 commits intoOct 28, 2026
Merged
Conversation
Log every request reaching http_callback() (mocked or blocked) and add a protected get_http_requests( $url = null ) accessor, cleared per test. Closes #66 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Note Generated by the AI delivery pipeline (lead-reviewer · Claude Opus 5.5). Review: ✅ PASS Re-review of 248564b: the earlier test-strength nice-to-have is resolved. Nice-to-haves:
|
Contributor
Author
|
Note Generated by the AI delivery pipeline (qa-engineer · Claude Opus 5.5). QA (re-run after 248564b): ✅ PASS
|
The test previously called tear_down_http() before setup_http(), so it would still pass if setup_http() stopped resetting. Call setup_http() again with a populated log instead (the filter registration is idempotent). Refs #66. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #66
Description
HttpRequestTraitnow records every outbound request it receives, so tests can assert on the request itself (method, headers, body, call count) without adding their ownpre_http_requestspy filter.What was done
HttpRequestTrait::http_callback()appends each request (urland parsedargs) to a per-test log before any mock lookup, so mocked and blocked requests are both recorded.protected get_http_requests( $url = null )returns the full log in order, or only the entries whose URL matches exactly.reset_http()clears the log, so it is empty at the start of each test and after teardown.args, and the limitation that only requests reaching the priority-10 filter are logged.Tests/Integration/testHttpRequestTrait.php(9 new methods) covering order, parsed args, exact-URL filtering, response lists, blocked requests, and reset on setup and teardown.How to test
npm run test:php:integration, orcomposer test-integrationwith a WP test suite installed). TheTest_HttpRequestTraittests must pass.get_http_requests()returns every request of the current test, in order, withurlandargs.get_http_requests( $url )returns only requests to that exact URL (no match on trailing slash, query string or case).composer phpcsandcomposer phpstan; both should pass with no baseline change.Type of change
Affected Features & Quality Assurance Scope
src/Integration/HttpRequestTrait.php: request logging,get_http_requests(), reset lifecycle, class docblock.Tests/Integration/testHttpRequestTrait.php: new coverage for the log.testHttpRequestTraitPropertyComposition.php,testHttpRequestTraitWithVirtualFilesystem.php) are unchanged and must stay green.HttpRequestTrait(any integration test class using it) gain a new protected method and a private property. No existing signature changes.Technical description
The log is a private array property,
$http_request_log, thathttp_callback()appends to as its first statement, so the existing lookup and blocking logic is untouched. The entry is[ 'url' => $url, 'args' => $args ], where$argsis what WordPress passes topre_http_requestafter default args are merged andhttp_request_argsfilters are applied. The property name avoids core's$blocked_http_requests(see #62).get_http_requests()returns the array unchanged when no URL is given. When a URL is given, it filters with a strict comparison and wraps the result inarray_values(), soget_http_requests( $url )[0]is valid.reset_http(), already called fromsetup_http()andtear_down_http(), empties the log, so the log only covers the window between setup and teardown.New dependencies
None.
Risks
get_http_requestsor a property named$http_request_logwould clash with the trait. Low likelihood; accepted per the issue.args(including headers and body) are held in memory only for the duration of the test.What was tested
QA report: #67 (comment)
get_http_requests()returns every request, in order, withurlandargsargsparsed (methodPOST,body)get_http_requests( $url )returns only requests to that exact URL[]; keys re-indexed from 0reset_http()fromsetup_http()makestestShouldStartWithEmptyLogOnSetupfail (the only failure of 40); restored, all greenTests/Integration/testHttpRequestTrait.php[OK] No errors, no baseline changeSuites:
npm run test:phpin wp-env (PHP 8.3): unit 126, integration 40, admin integration 3 — all OK.CI: phpcs, PHPStan, WP 5.9 / PHP 7.4, WP latest / PHP 8.0–8.5 — all green on 248564b.
PHP 7.4:
php -lon both changed files with PHP 7.4.30 — no errors.🤖 Generated with Claude Code