Tests: further Windows compatibility fixes#609
Conversation
|
Hello! 👋 Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project. Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation. Here are some useful Composer commands to get you started:
To run a single Behat test, you can use the following command: # Run all tests in a single file
composer behat features/some-feature.feature
# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123You can find a list of all available Behat steps in our handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request improves the cross-platform compatibility of the test suite by replacing inline wp eval commands with wp eval-file and switching from single to double quotes for command arguments in Behat feature files. These changes help avoid shell escaping issues, particularly on Windows. Feedback indicates that the transition to double quotes in features/post-block.feature was incomplete, as several instances (e.g., lines 1232 and 1248) were missed and should be updated for consistency.
| Scenario: Check if a post has blocks | ||
| Given a WP install | ||
| When I run `wp post create --post_title='Block Post' --post_content='<!-- wp:paragraph --><p>Hello</p><!-- /wp:paragraph -->' --porcelain` | ||
| When I run `wp post create --post_title="Block Post" --post_content="<!-- wp:paragraph --><p>Hello</p><!-- /wp:paragraph -->" --porcelain` |
There was a problem hiding this comment.
While this change to use double quotes for command arguments is correct for Windows compatibility, I've noticed that this fix has not been applied consistently throughout the file. There are other wp post create commands that still use single-quoted arguments containing spaces (e.g., on lines 1232, 1248). For complete Windows compatibility, all such instances should be updated to use double quotes.
There was a problem hiding this comment.
Pull request overview
This PR focuses on improving Windows compatibility for WP-CLI entity-command acceptance tests (Behat) and a small path-handling tweak in wp site empty --uploads.
Changes:
- Normalize upload file paths to forward slashes before checking for multisite
/sites/paths inSite_Command::empty_(). - Update multiple Behat scenarios to avoid shell-quoting pitfalls by switching to double quotes and using
wp eval-filewith generated.phpfiles instead of inlinewp eval .... - Mark several scenarios as
@skip-windowswhere they rely on Unix-specific shell features (e.g.,sed,wc, command substitution).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Site_Command.php | Normalizes real paths before /sites/ detection when deleting uploads. |
| features/user-import-csv.feature | Skips a CSV round-trip scenario on Windows. |
| features/user-application-password.feature | Replaces inline wp eval with wp eval-file scripts to avoid quoting issues. |
| features/term.feature | Switches command argument quoting to be more Windows-friendly. |
| features/term-recount.feature | Replaces inline wp eval with wp eval-file script. |
| features/site.feature | Skips several multisite scenarios on Windows due to Unix shell dependencies. |
| features/post.feature | Adjusts quoting (including EDITOR=...) to reduce Windows shell issues. |
| features/post-meta.feature | Skips a scenario on Windows and adjusts quoting for STDIN echo. |
| features/post-block.feature | Broad quoting adjustments and shifts some content into temp files for safer invocation. |
| features/comment.feature | Skips multi-digit ID scenarios on Windows due to shell command substitution usage. |
| features/comment-recount.feature | Replaces inline wp eval with wp eval-file script. |
Comments suppressed due to low confidence (1)
features/post-block.feature:1235
- This step uses
--attrs='{not valid json'to keep spaces together. Single quotes aren’t recognized as quoting in Windows shells, so the argument will be split and/or include literal quotes, changing the behavior of the test. Use double quotes for the--attrsvalue (or move the value into a temp file/STDIN) so the test remains cross-platform.
When I run `wp post create --post_title="Test" --post_content="<!-- wp:heading --><h2>Title</h2><!-- /wp:heading -->" --porcelain`
Then save STDOUT as {POST_ID}
When I try `wp post block update {POST_ID} 0 --attrs='{not valid json'`
Then STDERR should contain:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $realpath = $fileinfo->getRealPath(); | ||
| // Don't clobber subsites when operating on the main site | ||
| if ( $is_main_site && false !== stripos( $realpath, '/sites/' ) ) { | ||
| $normalized_realpath = str_replace( '\\', '/', $realpath ); | ||
| if ( $is_main_site && false !== stripos( $normalized_realpath, '/sites/' ) ) { | ||
| continue; |
There was a problem hiding this comment.
SplFileInfo::getRealPath() can return false. Passing that into str_replace() / stripos() will throw a TypeError in PHP 8+ and abort wp site empty --uploads. Add a guard (e.g. if ( false === $realpath ) { continue; }) or fall back to $fileinfo->getPathname() before normalizing/searching.
| And a block-content.txt file: | ||
| """ | ||
| <!-- wp:heading {"level":2} --><h2>Title 1</h2><!-- /wp:heading --><!-- wp:heading {"level":3} --><h3>Title 2</h3><!-- /wp:heading --> | ||
| """ | ||
| When I run `wp post create block-content.txt --post_title='Block Post' --porcelain` |
There was a problem hiding this comment.
These wp post create ... --post_title='…' commands still rely on single-quote shell quoting, which doesn’t work in Windows shells (the quotes become part of the argument). To keep the intended Windows-compatibility fix consistent, switch these to double quotes (or omit quotes when no spaces) across the file (search for --post_title=').
No description provided.