Repository navigation
Conversation
As of PHP 8.6, `fclose()`, `file_put_contents()`, and `copy()` return `false` when flushing or closing a stream fails. A userspace stream wrapper that does not implement `stream_flush()` is treated as failing to flush, so every write to `WP_Test_Stream` was reported as a failure, even though the data was written. This caused `Tests_Image_Editor_Imagick::test_streams` to fail on PHP 8.6, because `WP_Image_Editor_Imagick::write_image()` checks the return value of `file_put_contents()`. This also moves the `assertNotWPError()` assertion in that test before `$saved` is accessed as an array, so a failed save reports the actual error instead of a type error. See php/php-src@c07cc85. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Y86gwJZGdkh78pggUy4zs
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for this test-only PHP 8.6 compatibility and failure-reporting update.
No open issues 🎉
What changed in this PR
This test-only change updates WordPress’s in-memory test stream wrapper for PHP 8.6 and improves failure reporting in the Imagick stream test.
Changes:
- Adds
WP_Test_Stream::stream_flush(), returningtruebecause writes are stored directly in memory. - Moves the save-result assertion before array access so failed saves report the underlying
WP_Error.
| File | Description |
|---|---|
tests/phpunit/tests/image/editorImagick.php |
Checks for save errors before accessing the saved path. |
tests/phpunit/includes/class-wp-test-stream.php |
Implements successful no-op flushing for PHP 8.6 compatibility. |
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
lancewillett
left a comment
There was a problem hiding this comment.
Confirmed. I wrote 100 bytes through WP_Test_Stream with file_put_contents(), then closed a stream with fclose():
- PHP 8.6.0RC4 on trunk:
file_put_contents()returnsfalsewith all 100 bytes stored, andfclose()returnsfalse. - PHP 8.6.0RC4 on this branch:
100andtrue. - PHP 8.5.12:
100andtrue, with and without the change.
One note: CI can't show the test_streams fix, because the PHP 8.6 jobs skip it with "The image editor engine WP_Image_Editor_Imagick is not supported on this system". Moving assertNotWPError() ahead of the $saved['path'] read is a good change on its own.
Approving.
AI review · claude-opus-5-5
I forgot to note that technically no release of |
As of PHP 8.6, `fclose()`, `file_put_contents()`, and `copy()` return `false` when flushing or closing a stream fails. Before 8.6, these failures were silently ignored. A stream wrapper that does not implement `stream_flush()` is treated as failing to flush, so every write to `WP_Test_Stream` was reported as a failure on PHP 8.6, even though the data was written. This caused `Tests_Image_Editor_Imagick::test_streams` to fail. Writes to `WP_Test_Stream` are stored directly in memory, so `stream_flush()` has nothing to do and returns `true`. `WP_Test_Stream_Http_Mock` extends this class and inherits the fix. This also moves the `assertNotWPError()` assertion in `test_streams()` ahead of the first use of `$saved['path']`, so a failed save reports the actual error instead of `Cannot use object of type WP_Error as array`. Developed in #15476. Props desrosj, lancewillett. Fixes #66487. git-svn-id: https://develop.svn.wordpress.org/trunk@65278 602fd350-edb4-49c9-b593-d223f7449a82
As of PHP 8.6, `fclose()`, `file_put_contents()`, and `copy()` return `false` when flushing or closing a stream fails. Before 8.6, these failures were silently ignored. A stream wrapper that does not implement `stream_flush()` is treated as failing to flush, so every write to `WP_Test_Stream` was reported as a failure on PHP 8.6, even though the data was written. This caused `Tests_Image_Editor_Imagick::test_streams` to fail. Writes to `WP_Test_Stream` are stored directly in memory, so `stream_flush()` has nothing to do and returns `true`. `WP_Test_Stream_Http_Mock` extends this class and inherits the fix. This also moves the `assertNotWPError()` assertion in `test_streams()` ahead of the first use of `$saved['path']`, so a failed save reports the actual error instead of `Cannot use object of type WP_Error as array`. Developed in WordPress/wordpress-develop#15476. Props desrosj, lancewillett. Fixes #66487. Built from https://develop.svn.wordpress.org/trunk@65278 git-svn-id: http://core.svn.wordpress.org/trunk@64427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As of PHP 8.6,
fclose(),file_put_contents(), andcopy()returnfalsewhen flushing or closing a stream fails (php/php-src@c07cc85, bug #60110). Before 8.6, these failures were silently ignored.A userspace stream wrapper that does not implement
stream_flush()is treated as failing to flush (php_userstreamop_flush()returns-1when the method does not exist).WP_Test_Streamdoes not implement it, so on PHP 8.6 every write to it is reported as a failure, even though the data is written:file_put_contents()fclose()100truefalsefalseThis causes
Tests_Image_Editor_Imagick::test_streamsto fail on PHP 8.6, becauseWP_Image_Editor_Imagick::write_image()(correctly) checks the return value offile_put_contents().Changes
WP_Test_Stream::stream_flush(), returningtrue. Writes are stored directly in memory, so there is nothing to flush.WP_Test_Stream_Http_Mockextends this class and inherits the fix.assertNotWPError( $saved )intest_streamsbefore$saved['path']is accessed. Previously, a failed save surfaced asError: Cannot use object of type WP_Error as arrayinstead of the actualimage_save_error.This is a test-only change.
Testing
Ran against
trunkwith Imagick as the image editor (--group image,media):test_streamserrorsTests_Image_Editor_GD::test_flipalso fails on PHP 8.6, both with and without this change, which is unrelated. PHPCS passes on the changed files.Trac ticket: Core-66487.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigating the root cause, writing the change and the PR description, and running the tests.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code