Skip to content

Conversation

@Niellles
Copy link
Contributor

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.


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:

  • Are early indicators of breaking changes in future PHP versions.
  • Can clutter production logs, potentially causing unnecessary noise for users.
  • Have been historically reported as runtime bugs in this repository (#173, #241, #233, #169).

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.

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.
Copy link
Owner

@meyfa meyfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Niellles
Copy link
Contributor Author

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?

#241 only touched files in src/ (files changed). The offending line is present in current main.
So no, I don't believe that was previously fixed.

@meyfa meyfa changed the title CI: PHPUnit convert deprecations to errors chore: Let PHPUnit convert deprecations to errors Mar 23, 2025
@meyfa
Copy link
Owner

meyfa commented Mar 23, 2025

#241 only touched files in src/

I should have taken 5 more seconds to look at the output. My apologies.

@meyfa meyfa merged commit 7d74125 into meyfa:main Mar 23, 2025
8 checks passed
@Niellles
Copy link
Contributor Author

Niellles commented Mar 23, 2025

I should have taken 5 more seconds to look at the output. My apologies.

I should probably have fixed the test before leaving my comment, as this just got merged while I was fixing it.

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