Build/Test Tools: Mock external HTTP requests in wp_crop_image() URL tests - #14020
huzaifaalmesbah wants to merge 2 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Without OpenSSL, wrapper setup and cleanup emit warnings and can leak the mock HTTPS wrapper.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Replaces live HTTP dependencies in wp_crop_image() URL tests with an in-memory stream fixture.
Changes:
- Registers
WP_Test_Streamas an HTTPS mock. - Removes external HTTP and OpenSSL test requirements.
- Adds stream-wrapper cleanup.
| File | Description |
|---|---|
tests/phpunit/tests/image/functions.php |
Mocks image URLs and restores stream state after tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if ( ! in_array( 'https', stream_get_wrappers(), true ) ) { | ||
| stream_wrapper_restore( 'https' ); | ||
| } |
|
Four changes needed before commit:
AI review · |
lancewillett
left a comment
There was a problem hiding this comment.
Changes requested: see the four items in #14020 (comment)
AI review · claude-opus-5-5
|
Thanks @lancewillett for the thorough review and guidance! Updated in 3b301a0:
Verified locally with PHPCS and PHPUnit across both single-site and multisite suites. |

Description
In
tests/phpunit/tests/image/functions.php,test_wp_crop_image_with_url()was annotated with@group external-httpbecause it performed a live HTTP request tohttps://s.w.org/screenshots/3.9/dashboard.pngvia PHP's stream wrapper during image loading. Additionally,test_wp_crop_image_should_fail_with_wp_error_object_if_url_does_not_exist()made an unmocked live request towordpress.org.This PR replaces the live network requests by mocking the
httpsstream wrapper with Core'sWP_Test_Streamin-memory fixture stream, removing live network dependencies and removing@group external-httpfromtest_wp_crop_image_with_url().Testing Instructions
--group external-http:Trac ticket: https://core.trac.wordpress.org/ticket/63914
Use of AI Tools
AI assistance: Yes
Tool(s): Google Antigravity
Model(s): Gemini 3.8 Flash
Used for: Brainstorming stream wrapper mocking with WP_Test_Stream and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.