Overhaul install-wp-tests.sh and mock oembed tests#1555
Conversation
This commit significantly updates the `tests/bin/install-wp-tests.sh` script
to ensure it can reliably set up a WordPress testing environment.
Key improvements include:
- **Switched to GitHub:** WordPress test suite files (`wp-tests-config-sample.php`,
PHPUnit `includes` directory) are now fetched from the official
`WordPress/wordpress-develop` GitHub repository instead of outdated SVN URLs.
Uses `svn export` with a `git clone` fallback.
- **Modernized Version Handling:**
- Correctly determines the GitHub reference (`trunk` or version tags) for
`WP_VERSION` (latest, specific versions like X.Y, X.Y.Z).
- Uses `jq` if available (with a `grep`/`sed` fallback) for robustly
parsing the latest WordPress version from the WordPress API.
- **Improved Directory Management:**
- `WP_TESTS_DIR` and `WP_CORE_DIR` now default to relative paths
(`tests/tmp/`) within the project, instead of global `/tmp` locations.
- Directory cleanup logic is safer and more reliable.
- **Removed Obsolete Components:**
- Removed download of a custom `wp-mysqli/db.php` file (no longer needed).
- Removed installation of the `rest-api` plugin (now part of WP core).
- **Enhanced Robustness:**
- Added comprehensive dependency checks at startup for `svn`, `git`,
`curl`/`wget`, `tar`, `mysql`, and `mysqladmin`.
- Improved error handling for downloads and critical operations.
- Removed `set -x` for cleaner output; retained `set -e`.
- Added a user-agent string to `wget` calls.
- **Updated Documentation:**
- Internal comments and usage instructions have been thoroughly updated to
reflect all changes.
These changes address multiple issues that previously prevented the script
from functioning correctly with current WordPress development practices.
Resolve CLAUDE.md conflict by keeping develop's version. Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Skip --protocol=tcp when DB_HOST is localhost (allows Unix socket) - Create wp-content/uploads directory after WP core install Co-Authored-By: Claude Opus 4.6 <[email protected]>
WordPress 6.9 added path traversal protection in wp_mkdir_p() that rejects paths containing '../'. The script's SCRIPT_DIR-relative defaults produced paths like tests/bin/../tmp/wordpress which triggered this check, causing wp_upload_bits() to fail in tests. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace flaky live API calls to YouTube and Twitter with mocked responses via pre_http_request filter. Simplify test_values_cached to validate cache entry structure rather than exact content. Tests now run in ~7s instead of ~63s. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the WordPress testing environment setup and reliability. The Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request provides a significant overhaul of the install-wp-tests.sh script, modernizing it with GitHub integration, dependency checks, and improved error handling. It also smartly mocks oembed HTTP requests in the PHPUnit tests, which will make them faster and more reliable by removing external dependencies. The changes are well-executed and greatly improve the project's testing infrastructure. I have a couple of minor suggestions for the shell script to enhance its robustness and maintainability.
The install script now defaults to relative paths (tests/tmp/), so the CI env vars must be exported before the script runs, not after. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
The script overhaul changed defaults to script-relative paths, which broke CI and required workarounds. Restore the original /tmp/ defaults that match standard WordPress test environment conventions. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
tests/bin/install-wp-tests.shfor modern WordPress — fetches test suite from GitHub (with SVN-to-git fallback), adds dependency checks, improved error handling, and better documentation--protocol=tcpwhenDB_HOSTislocalhostso MySQL uses Unix socket instead of resolving to a Docker/network IPwp-content/uploadsdirectory after WordPress core extraction (required by test suite)pre_http_requestfilter — eliminates flaky Twitter/YouTube API dependencies and reduces test time from ~63s to ~7sTest plan
bash tests/bin/install-wp-tests.sh <db_name> <db_user> <db_pass>completes successfullyvendor/bin/phpunitpasses all 214 tests (701 assertions)🤖 Generated with Claude Code