Opened 3 years ago
Last modified 7 days ago
#60110 new enhancement
PHPUnit test for _deprecated_hook()
| Reported by: | pbearne | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | tests |
Description
Change History (6)
This ticket was mentioned in PR #5796 on WordPress/wordpress-develop by @pbearne.
3 years ago
#1
- Keywords has-patch has-unit-tests added
This ticket was mentioned in PR #15476 on WordPress/wordpress-develop by @desrosj.
7 days ago
#5
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(), returningtrue. Writes are stored directly in memory, so there is nothing to flush.WP_Test_Stream_Http_Mockextends this class and inherits the fix. - Moves
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 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:
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
@desrosj commented on PR #15476:
7 days ago
#6
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 $savedpath 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Since this is about adding tests and not a general build or test tooling change, I'm reassigning it to the relevant component.