Removes three calls to ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suite above PHP 8.1 - #942
Conversation
ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suiteReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() in the test suite above PHP 8.1
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR updates the PHPUnit test suite to avoid PHP 8.5 deprecation notices from ReflectionProperty::setAccessible() / ReflectionMethod::setAccessible() by only calling setAccessible( true ) on PHP versions where it still has an effect (pre-8.1). This keeps the tests compatible with older PHP versions while removing the deprecation noise on newer versions.
Changes:
- Wrapped
ReflectionProperty::setAccessible( true )calls in PHP version guards inTwo_Factor_Coretests. - Wrapped
ReflectionMethod::setAccessible( true )call in a PHP version guard in the TOTP provider tests. - Ensures PHP 8.5+ test runs no longer emit
setAccessible()deprecation notices.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/providers/class-two-factor-totp.php |
Guard ReflectionMethod::setAccessible( true ) for PHP < 8.1 in the reflection helper to avoid PHP 8.5 deprecations. |
tests/class-two-factor-core.php |
Guard ReflectionProperty::setAccessible( true ) for PHP < 8.1 in two reflection-based test helpers/paths to avoid PHP 8.5 deprecations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What?
Removes three calls to
ReflectionProperty::setAccessible()/ReflectionMethod::setAccessible()for PHP 8.1+ in the test suite.Fixes #
Why?
See: https://www.php.net/manual/de/reflectionmethod.setaccessible.php
Since PHP 8.1, reflection properties and methods are accessible without calling
setAccessible( true ), making the call a no-op. As of PHP 8.5, calling it is deprecated and emits aPHP Deprecatednotice, which was showing up as noise in test runs (tests/class-two-factor-core.php:168,:2374,tests/providers/class-two-factor-totp.php:457)................................................................ 63 / 232 ( 27%) [23-Jul-2026 20:30:55 UTC] PHP Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 168 .......Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 168 [23-Jul-2026 20:30:55 UTC] PHP Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 2398 Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1.Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1...Received a non-notice error: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php on line 2398 ...................................F................ 126 / 232 ( 54%) ............................................................... 189 / 232 ( 81%) [23-Jul-2026 20:30:57 UTC] PHP Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/providers/class-two-factor-totp.php on line 457 ...................................... Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/two-factor/tests/providers/class-two-factor-totp.php on line 457How?
Deleted the three now-redundant
setAccessible( true )lines. No behavior change — the reflection objects were already accessible without it.Use of AI Tools
Testing Instructions
ReflectionProperty::setAccessible() is deprecated/ReflectionMethod::setAccessible() is deprecatednotices no longer appear.Changelog Entry