Conversation
`WP_Debug_Data::get_wp_media()` ran `gs --version` without checking that `gs` exists. When it is not installed, the shell prints an error on stderr (visible in the terminal, WP-CLI and PHPUnit output) even though the "Not available" case is already handled. Check that `gs` exists with `command -v` before running it. Add tests covering both cases: `gs` available and missing. See #66245.
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @accolette. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
When Ghostscript (
gs) is not installed,WP_Debug_Data::get_wp_media()runsgs --versionthroughexec().exec()only captures stdout, so the shell prints an error on stderr (for examplesh: 1: gs: not found, the exact wording depends on the shell). It is visible in the terminal, in WP-CLI and in PHPUnit output.The "Ghostscript version" field is already correctly reported as "Not available", so this change only removes the unwanted shell output. The reported result does not change.
Changes
gsexists withcommand -vbefore runninggs --version.tests/phpunit/tests/admin/wpDebugData.phpwith two tests on the Ghostscript field returned byWP_Debug_Data::debug_data():gsis available (a fakegsscript is added to thePATH): the version is reported.gsis missing (thePATHdoes not contain it): the field is reported as "not available".Testing
Run:
npm run test:php -- --filter Tests_Admin_wpDebugDatash: 1: gs: not foundis printed in the output.The tests cannot assert on the message itself, because it is written to stderr by the child process and not by PHP. They check that the reported value is unchanged, and the message is checked by looking at the output. WP-CLI steps to reproduce are in the ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/66245
Use of AI Tools
AI assistance: Yes. Tool(s): Claude (Anthropic). Used for: helping me understand the problem, looking up the affected version, suggesting reproduction commands, and drafting the PHPUnit tests, the Trac ticket text and this description. I found the bug, reproduced it, ran the tests and tested the patch.
The fix was suggested by Chouby.