chore: Let PHPUnit convert deprecations to errors#243
Merged
meyfa merged 1 commit intomeyfa:mainfrom Mar 23, 2025
Merged
Conversation
Changes PHPUnit config to: - Enable error reporting - Error on deprecation warnings Note that due to PHPUnits way of parsing warnings, not all deprecations may lead to errors.
meyfa
approved these changes
Mar 22, 2025
Owner
meyfa
left a comment
There was a problem hiding this comment.
LGTM
In the CI logs for 8.4, there is a warning:
PHP Deprecated: SVG\Tests\Nodes\Shapes\SVGPolygonalShapeSubclass::__construct(): Implicitly marking parameter $points as nullable is deprecated, the explicit nullable type must be used instead in /home/runner/work/php-svg/php-svg/tests/Nodes/Shapes/SVGPolygonalShapeTest.php on line 15
Wasn't this fixed in #241?
Contributor
Author
#241 only touched files in |
Owner
I should have taken 5 more seconds to look at the output. My apologies. |
Contributor
Author
I should probably have fixed the test before leaving my comment, as this just got merged while I was fixing it. |
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.
Changes PHPUnit config to:
Note that due to PHPUnits way of parsing warnings, not all deprecations may lead to errors.
The Issue
Currently, PHPUnit is not properly configured to report deprecation warnings, as noted in #241. This means that while our CI tests pass, they do not catch potential future breakages introduced by deprecated functionality.
Why This Matters
Deprecation warnings:
Given the repository's history of treating deprecations as bugs in maintainer's past comments (PR #177 Review), it makes sense to ensure CI catches these issues proactively.
Limitations & Potential Workarounds
Due to the way PHPUnit 9 handles deprecations, only warnings triggered directly during test execution will cause failures. Deprecations that occur indirectly—such as in constructors of abstract classes—may not be caught if they are invoked through child classes. Since PHPUnit does not detect these deprecations as part of the test execution path, they may go unnoticed.
As all deprecation warnings are printed—only direct warnings trigger errors, one possible workaround is to wrap PHPUnit in a shell script that parses its output, explicitly looking for
"Deprecation:"messages. This approach (or other potential solutions) can be discussed in the comments or in a new issue. I'm happy to implement this or explore alternative suggestions if anyone has ideas.