Skip to content

Tests: Implement stream_flush() in WP_Test_Stream for PHP 8.6 - #15476

Closed
desrosj wants to merge 2 commits into
WordPress:trunkfrom
desrosj:php86-test-stream-flush
Closed

desrosj wants to merge 2 commits into
WordPress:trunkfrom
desrosj:php86-test-stream-flush

Conversation

@desrosj

@desrosj desrosj commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

As of PHP 8.6, fclose(), file_put_contents(), and copy() return false when 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 -1 when the method does not exist). WP_Test_Stream does 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() Bytes stored fclose()
PHP 8.5.12 100 100 true
PHP 8.6.0RC4 false 100 false

This causes Tests_Image_Editor_Imagick::test_streams to fail on PHP 8.6, because WP_Image_Editor_Imagick::write_image() (correctly) checks the return value of file_put_contents().

Changes

  • Implements WP_Test_Stream::stream_flush(), returning true. Writes are stored directly in memory, so there is nothing to flush. WP_Test_Stream_Http_Mock extends this class and inherits the fix.
  • Moves assertNotWPError( $saved ) in test_streams before $saved['path'] is accessed. Previously, a failed save surfaced as Error: Cannot use object of type WP_Error as array instead of the actual image_save_error.

This is a test-only change.

Testing

Ran against trunk with Imagick as the image editor (--group image,media):

Before After
PHP 8.6.0RC4 test_streams errors Passes
PHP 8.5.12 Passes Passes

Tests_Image_Editor_GD::test_flip also 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

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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(), returning true because 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

@desrosj
desrosj marked this pull request as ready for review November 5, 2026 00:51
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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:

Props desrosj, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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() returns false with all 100 bytes stored, and fclose() returns false.
  • PHP 8.6.0RC4 on this branch: 100 and true.
  • PHP 8.5.12: 100 and true, 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

@desrosj

desrosj commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

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.

I forgot to note that technically no release of imagick supports PHP 8.6 yet. However, Claude built a Docker image locally with ImageMagick support by building directly from the project's primary branch.

wporg-sync pushed a commit that referenced this pull request Nov 5, 2026
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
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65278
GitHub commit: 8c41f66

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 5, 2026
@github-project-automation github-project-automation Bot moved this from In review to Done in WordPress Project Build Tooling Nov 5, 2026
@desrosj
desrosj deleted the php86-test-stream-flush branch November 5, 2026 16:22
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 5, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants