Skip to content

Tests: Add helpers for accessing protected properties in image editor test cases - #15842

Closed
robelsust wants to merge 2 commits into
WordPress:trunkfrom
robelsust:feature/66584-image-editor-gd-helper
Closed

robelsust wants to merge 2 commits into
WordPress:trunkfrom
robelsust:feature/66584-image-editor-gd-helper

Conversation

@robelsust

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/66584

Description

In Tests_Image_Editor_GD, multiple test methods duplicate several lines of ReflectionProperty boilerplate to read or set protected properties such as $editor->image and $editor->size. This was noted during review of #66113 (comment).

Changes

  • Adds get_property_value( $editor, $property_name = 'image' ) and set_property_value( $editor, $property_name, $value ) to the shared WP_Image_UnitTestCase base class (tests/phpunit/tests/image/base.php).
  • Guards setAccessible( true ) with PHP_VERSION_ID < 80100 to ensure safe execution on PHP 8.1+ and avoid PHP 8.5 deprecation notices.
  • Refactors Tests_Image_Editor_GD, Tests_Image_Editor_Imagick, and Tests_Image_Editor to use the helpers.
  • Adds dedicated unit tests in Tests_Image_Editor_GD::test_get_and_set_property_value().

Verification

  • vendor/bin/phpcs passes with 0 errors across all modified files.
  • vendor/bin/phpunit --group wp-image-editor-gd passes (43 tests, 119 assertions).
  • vendor/bin/phpunit --filter 'Tests_Image_Editor::' passes (22 tests, 42 assertions).

@github-actions

github-actions Bot commented Nov 9, 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 therssoftware, 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.

The refactor itself is good. All seven ReflectionProperty blocks in the image tests now go through the two helpers. Putting them in WP_Image_UnitTestCase fits better than a private method, since three classes share them. At 8651be5, the GD, Imagick and editor tests pass the same as trunk in single site and multisite, and PHPCS is clean.

Please trim it to just the refactor:

  1. Drop test_get_and_set_property_value(). It tests the test helpers, not WordPress. The rotate, flip, get_size() and get_suffix() tests already use both helpers and would fail if either broke.
  2. Drop the new annotations on existing tests.
    • @ticket 39055 doesn't belong to these tests: the trunk commits that cite it are WP_Query orderby tests.
    • @ticket 66584 marks a test that covers that ticket's bug. This ticket is a cleanup, so it doesn't belong on test_get_size(), test_get_suffix(), the rotate and flip tests, or the helper docblocks.
    • The @covers lines are unrelated to this change.

After that, the diff is just the two helpers and the call sites.

AI review · claude-opus-5-5

… test cases.

Introduces `get_property_value()` and `set_property_value()` helper methods on `WP_Image_UnitTestCase` to eliminate repeated `ReflectionProperty` boilerplate and handle PHP 8.1+ / PHP 8.5+ deprecation-safe accessibility across image editor test classes. Refactors `Tests_Image_Editor_GD`, `Tests_Image_Editor_Imagick`, and `Tests_Image_Editor` to use the new helpers.

Props therssoftware.
See #66584.
@robelsust
robelsust force-pushed the feature/66584-image-editor-gd-helper branch from 8651be5 to 18abf85 Compare November 9, 2026 15:57
@robelsust

Copy link
Copy Markdown
Author

Thanks for the review, @lancewillett!

Updated in the latest push:

  • Dropped test_get_and_set_property_value().
  • Removed all added @ticket and @covers annotations from existing tests and the helper DocBlocks.
  • Trimmed the diff strictly to the two helpers in WP_Image_UnitTestCase and their call sites.

All GD, Imagick, and editor test suites pass locally in both single site and multisite, and PHPCS is clean. Ready for another look.

@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.

Approving at e3e8657. The diff is now just the two helpers and their seven call sites.

  • The GD, Imagick and editor tests match trunk in single site and multisite: 78 tests, 166 assertions.
  • With both helpers broken, all seven refactored tests fail (rotate and flip for GD and Imagick, plus test_generate_filename(), test_get_size() and test_get_suffix()). So every call site goes through them.
  • PHPCS is clean, and the change applies cleanly to trunk.

AI review · claude-opus-5-5

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Nov 9, 2026
…perties.

Replace the repeated `ReflectionProperty` setup in the image editor tests with two helpers on `WP_Image_UnitTestCase`.

Developed in: #15842

Props therssoftware, sanjith2023.
Fixes #66584.


git-svn-id: https://develop.svn.wordpress.org/trunk@65353 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 9, 2026
…perties.

Replace the repeated `ReflectionProperty` setup in the image editor tests with two helpers on `WP_Image_UnitTestCase`.

Developed in: WordPress/wordpress-develop#15842

Props therssoftware, sanjith2023.
Fixes #66584.

Built from https://develop.svn.wordpress.org/trunk@65353


git-svn-id: http://core.svn.wordpress.org/trunk@64493 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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants