Fix PHP 8.3/8.5 deprecations in TestCaseTrait reflection helpers - #33
Merged
Conversation
ReflectionProperty::setValue() emits a deprecation as of PHP 8.3 when its first argument is neither null nor an object, which happened whenever set_reflective_property() targeted a static property (the caller passes a class name). Static properties are now set with an explicit null target. Reflection*::setAccessible() has no effect since PHP 8.1 and is deprecated as of PHP 8.5. The calls are now routed through a helper that skips them on PHP 8.1+, keeping them for the still-supported PHP 7.4 and 8.0. Adds a regression test covering both helpers plus a deprecation-free assertion. Verified on PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5. Fixes #29 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Covers the version that surfaced the setAccessible() deprecation in #29, so the regression test in testTestCaseTrait.php guards it going forward. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #29
Changes
setValue()on static properties.set_reflective_property()forwarded$instancestraight toReflectionProperty::setValue(), but callers pass a class name when targeting a static property. Static properties are now set with an explicitnulltarget:setAccessible(). No-op since PHP 8.1, deprecated as of 8.5, but still required on 7.4/8.0. All four call sites now route through a privateset_reflector_accessible()helper that returns early whenPHP_VERSION_ID >= 80100.getNonPublicPropertyValue()picked up anisStatic()check so it no longer relies on the object argument being silently ignored for static properties. Behaviour is unchanged.The library keeps its
>=7.4compatibility — the version guard is the reasonsetAccessible()is kept rather than deleted.Testing
Tests/Unit/testTestCaseTrait.phpcovers instance/static property set+get (via both a class name and an instance), non-public method invocation, and asserts noE_DEPRECATEDis emitted. That last test fails against the old implementation on both 8.3 and 8.5, so it is a real guard.Notes for the reviewer
get_reflective_property()usesReflectionClass::getProperty(), which does not find a private property declared on a parent class.🤖 Generated with Claude Code