Skip to content

Overhaul install-wp-tests.sh and mock oembed tests#1555

Merged
jtsternberg merged 10 commits into
developfrom
fix/install-wp-tests-script
Mar 3, 2026
Merged

Overhaul install-wp-tests.sh and mock oembed tests#1555
jtsternberg merged 10 commits into
developfrom
fix/install-wp-tests-script

Conversation

@jtsternberg
Copy link
Copy Markdown
Member

@jtsternberg jtsternberg commented Mar 2, 2026

Summary

  • Overhaul tests/bin/install-wp-tests.sh for modern WordPress — fetches test suite from GitHub (with SVN-to-git fallback), adds dependency checks, improved error handling, and better documentation
  • Fix localhost DB connection — skip --protocol=tcp when DB_HOST is localhost so MySQL uses Unix socket instead of resolving to a Docker/network IP
  • Create missing wp-content/uploads directory after WordPress core extraction (required by test suite)
  • Mock oembed HTTP requests in ajax tests via pre_http_request filter — eliminates flaky Twitter/YouTube API dependencies and reduces test time from ~63s to ~7s
  • Add GitHub Actions PHPUnit workflow with matrix testing across PHP 7.4–8.3 and WP 6.3–latest

Test plan

  • bash tests/bin/install-wp-tests.sh <db_name> <db_user> <db_pass> completes successfully
  • vendor/bin/phpunit passes all 214 tests (701 assertions)
  • Oembed tests no longer make live network requests
  • CI PHPUnit workflow passes across all matrix combinations

🤖 Generated with Claude Code

jtsternberg and others added 6 commits May 27, 2025 11:05
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]>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 install-wp-tests.sh script has been modernized to handle current WordPress development practices, including robust dependency management and path resolution. Additionally, AJAX tests involving oEmbeds are now more stable and faster due to the introduction of HTTP request mocking, preventing flaky test failures caused by external API calls.

Highlights

  • Overhauled install-wp-tests.sh Script: The WordPress test installation script has been extensively modernized to fetch the test suite from GitHub, include robust dependency checks, improve error handling, and provide better documentation.
  • Fixed Localhost DB Connection: The script now correctly handles localhost database connections by skipping the --protocol=tcp flag, ensuring MySQL uses Unix sockets instead of attempting to resolve a network IP.
  • Resolved WP 6.9+ Path Traversal: Canonicalized WP_TESTS_DIR and WP_CORE_DIR paths to prevent issues with WordPress 6.9+ rejecting paths containing ../.
  • Ensured wp-content/uploads Directory Creation: The wp-content/uploads directory is now explicitly created after WordPress core extraction, which is required by the WordPress test suite.
  • Mocked oEmbed HTTP Requests: AJAX tests now mock oEmbed HTTP requests via the pre_http_request filter, eliminating flaky Twitter/YouTube API dependencies and significantly reducing test execution time from ~63s to ~7s.

🧠 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
  • tests/bin/install-wp-tests.sh
    • Updated script header with detailed documentation, usage, and examples.
    • Implemented dependency checks for svn, git, tar, mysql, mysqladmin, curl, and wget.
    • Modified download function for improved error handling and curl/wget usage.
    • Introduced get_latest_wp_version function to fetch WordPress version from API.
    • Switched test suite fetching from SVN to GitHub's SVN bridge with Git clone fallback.
    • Canonicalized WP_TESTS_DIR and WP_CORE_DIR paths to prevent issues with WordPress 6.9+.
    • Removed installation of custom wp-mysqli db.php and REST API plugin.
    • Ensured wp-content/uploads directory is created.
    • Adjusted database connection logic to avoid --protocol=tcp for localhost connections.
    • Added verbose echo statements for better script execution feedback.
  • tests/test-cmb-ajax.php
    • Added pre_http_request filter to set_up() to mock oEmbed HTTP requests.
    • Removed the pre_http_request filter in tear_down().
    • Implemented mock_oembed_request method to return predefined JSON responses for YouTube and Twitter oEmbed API calls.
    • Simplified the test_values_cached assertion logic to verify generic cached oEmbed data instead of specific content.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/bin/install-wp-tests.sh Outdated
Comment thread tests/bin/install-wp-tests.sh Outdated
jtsternberg and others added 4 commits March 2, 2026 18:06
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]>
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]>
@jtsternberg jtsternberg merged commit de87163 into develop Mar 3, 2026
17 checks passed
@jtsternberg jtsternberg deleted the fix/install-wp-tests-script branch March 3, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant