Add support for installing WordPress from an arbitrary ZIP archive - #351
Conversation
Behat suites can now install WordPress from a ZIP archive instead of downloading it from WordPress.org, by pointing the new `WP_CLI_TEST_CORE_ZIP` environment variable at either a local file or an HTTP(S) URL. This makes it possible to run the functional tests against a WordPress build that has not been released, such as the `wordpress.zip` and `develop.zip` artifacts produced by the WordPress core build process. The archive may contain WordPress at its root or wrapped in a single folder, so that both the `wordpress/` layout used by WordPress.org releases and the `build/` layout used by some core build artifacts work. Archives are extracted once and cached, keyed by their contents. `WP_VERSION` keeps governing which version-specific tags are filtered out, as the version of a development build cannot be compared meaningfully, and defaults to `trunk` when an archive is configured. Steps requesting an explicit version, such as `Given a WP 6.4.2 installation`, continue to download that version and ignore the archive. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CE81GsxUY597AdaMP1NXzk
|
Warning Review limit reached
Next review available in: 26 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe test runner now accepts local or remote WordPress core ZIP archives. FeatureContext resolves, validates, extracts, and caches these archives by version or content hash. Documentation and PHPUnit tests cover configuration, supported layouts, cache behavior, and error handling. ChangesWordPress core ZIP support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant FeatureContext
participant WordPressArchive
participant CoreCache
TestRunner->>FeatureContext: configure WP_CLI_TEST_CORE_ZIP
FeatureContext->>WordPressArchive: resolve local or remote archive
WordPressArchive-->>FeatureContext: validate readable archive
FeatureContext->>WordPressArchive: extract WordPress files
WordPressArchive-->>CoreCache: provide extracted installation
FeatureContext->>CoreCache: use archive-based cache
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Line 133: Resolve the MD003 warning for the “WordPress Archive” heading by
either updating the Markdown lint configuration to permit the existing ATX
heading hierarchy or changing the heading to the repository-approved
setext-compatible form; preserve the document’s heading structure and ensure
markdownlint-cli2 passes.
In `@src/Context/FeatureContext.php`:
- Around line 821-825: Update the rename fallback in the directory move flow to
create $dest_dir before calling self::copy_dir( $source_dir, $dest_dir ).
Preserve the existing rename path, and ensure the destination directory exists
when rename() fails so root-level files can be copied successfully.
In `@tests/tests/TestCoreZip.php`:
- Around line 18-30: Update TestCoreZip::set_up() to capture the original
WP_CLI_TEST_CORE_ZIP value, then have tear_down() restore that value after
cleanup instead of only clearing it. Reset FeatureContext::$core_zip after
restoration so later tests retain the original archive configuration.
- Around line 172-185: In get_core_cache_dir() and reset_core_zip(), guard each
ReflectionMethod/ReflectionProperty::setAccessible() call with a PHP_VERSION_ID
check for runtimes below 8.1, and update composer.json’s minimum PHP requirement
to >=8.1 so the supported runtime matches the reflection behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7d00e01c-302a-49d2-8b04-63c3bb6a6faf
📒 Files selected for processing (5)
.readme-partials/USING.mdREADME.mdbin/run-behat-testssrc/Context/FeatureContext.phptests/tests/TestCoreZip.php
There was a problem hiding this comment.
Pull request overview
This PR extends the WP-CLI Behat test framework to allow installing WordPress core from an arbitrary ZIP archive (local path or HTTP(S) URL) via the new WP_CLI_TEST_CORE_ZIP environment variable, enabling functional tests against unreleased WordPress build artifacts while preserving existing version-driven behavior.
Changes:
- Add ZIP resolution (local/remote), extraction, and cache-directory derivation keyed by archive contents in the Behat
FeatureContext. - Add PHPUnit coverage for archive layouts (
wordpress/,build/, flat), destination replacement, and cache-dir derivation rules. - Document the new environment variable and default
WP_VERSIONbehavior; defaultWP_VERSION=trunkwhen an archive is configured.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Context/FeatureContext.php |
Implements archive resolution/download, content-hash cache keying, and extraction logic used by the Behat install workflow. |
tests/tests/TestCoreZip.php |
Adds unit tests for ZIP extraction behavior and cache directory derivation when an archive is configured. |
README.md |
Documents WP_CLI_TEST_CORE_ZIP usage and interaction with WP_VERSION. |
.readme-partials/USING.md |
Mirrors the README “WordPress Archive” documentation in the generated partials. |
bin/run-behat-tests |
Defaults WP_VERSION to trunk when WP_CLI_TEST_CORE_ZIP is set and WP_VERSION is not. |
Suppressed comments (1)
src/Context/FeatureContext.php:825
- If the fast-path
rename()fails, the fallbackcopy_dir()is called with a destination that may not exist.copy_dir()'s own docblock says the destination directory must exist, andcopy()will fail when the extracted WordPress root contains files at its top level (e.g.wp-load.php). Ensure$dest_diris created before callingcopy_dir().
// Both directories live in the system temp folder, so a rename is
// normally possible and avoids copying thousands of files.
if ( ! @rename( $source_dir, $dest_dir ) ) {
self::copy_dir( $source_dir, $dest_dir );
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes the unit test failure on PHP < 8.0, where calling `ZipArchive::getStatusString()` on an archive that failed to open errors out with "Invalid or uninitialized Zip object". The error code returned by `ZipArchive::open()` is now used instead. Creates the destination directory before falling back to `copy_dir()`, which copies into an existing directory and would otherwise fail to copy the files at the root of the archive. Rejects archives holding entries that point outside of the directory they are extracted into. `ZipArchive::extractTo()` normalizes such entries rather than following them, but an archive containing them is malformed for our purposes on any PHP version. Drops the reflection from the tests, which called `Reflection*::setAccessible()`, deprecated as of PHP 8.5. The cache directory is now derived through a public method, and the resolved archive is memoized against the environment variable it came from, so a change of that variable is picked up rather than served from the memoized value. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CE81GsxUY597AdaMP1NXzk
Behat suites can now install WordPress from a ZIP archive instead of
downloading it from WordPress.org, by pointing the new
WP_CLI_TEST_CORE_ZIPenvironment variable at either a local file or anHTTP(S) URL.
This makes it possible to run the functional tests against a WordPress
build that has not been released, such as the
wordpress.zipanddevelop.zipartifacts produced by the WordPress core build process.The archive may contain WordPress at its root or wrapped in a single
folder, so that both the
wordpress/layout used by WordPress.orgreleases and the
build/layout used by some core build artifacts work.Archives are extracted once and cached, keyed by their contents.
WP_VERSIONkeeps governing which version-specific tags are filteredout, as the version of a development build cannot be compared
meaningfully, and defaults to
trunkwhen an archive is configured.Steps requesting an explicit version, such as
Given a WP 6.4.2 installation, continue to download that version and ignore the archive.Co-Authored-By: Claude Opus 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01CE81GsxUY597AdaMP1NXzk
Summary by CodeRabbit
New Features
WP_VERSIONtotrunkwhen using a configured archive without an explicit version.Documentation