-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distinguish between self, direct and indirect deprecations #5689
Comments
Can you please elaborate what the differences between self, direct, and indirect deprecations are as well as why limiting the reporting of deprecations to only your code (excluding deprecations triggered by code in |
self deprecations are deprecations triggered in your own code. Excluding all deprecations triggered in vendor code would not report direct deprecations, which are still something that should be solved by the project.
|
See https://github.com/symfony/phpunit-bridge/blob/6.3/DeprecationErrorHandler/Deprecation.php for the logic. |
Thank you, @stof, for explaining this. |
If implemented, @stof comment above can be used in the docs about the feature directly, nice! |
I am confident that this can and will be implemented. |
Sorry to bother you again, @stof, but I need to rephrase your explanation of
In the above, |
Here is my first attempt at implementig the detection of the above: phpunit/src/Runner/ErrorHandler.php Lines 234 to 267 in ffc0078
|
|
|
I think we need a configurable list of functions/methods for which stack frames should be skipped. |
This is the event log used in an end-to-end test for the current implementation:
|
The idea is that if a library uses a package like Symfony's error handler has a Do you think, PHPUnit should ship a list of well-known deprecation functions that can be extended via phpunit.xml? Or should this list be empty by default, e.g. every project that uses any Symfony component has to configure |
I think the list of deprecation functions should be empty by default and configurable through PHPUnit's XML configuration file. |
Empty by default sounds good, assuming it's possible for plugins to populate it? That way a Symfony plugin could populate the list with "well known deprecations in the Symfony world", Laravel could do the same for itself, etc. PHPUnit doesn't need to know the names. |
The XML configuration file should be the only means of configuring this. I have no plan to allow populating this list through plugins. AFAIK, Symfony, for example, creates a PHPUnit XML configuration file already for new projects. Adding the relevant configuration to that should be trivial. |
Configuring deprecation triggering functions/methods is now implemented. Here is an example from the test suite:
phpunit/tests/end-to-end/self-direct-indirect/_files/deprecation-trigger-function/phpunit.xml Lines 17 to 19 in 10ac9a7
|
The "only" thing left to implement is using the information whether a deprecation is self, direct, or indirect for selecting which deprecations to report. Since PHPUnit 10, we have the I think we should deprecate the The new functionality that is the topic of this issue should be controlled through these new attributes:
Does that make sense? |
To avoid migration pain, the default value for all three attributes, The XML configuration file with best practice defaults that can be generated using The XML configuration file migrator replaces |
This has now been merged into A huge "Thank you!" to everyone who provided input and contributed feedback along the way. |
@sebastianbergmann A huge thanks back for implementing this feature! |
Context
We've recently upgraded PHPUnit to version 10.5, up from 9.6, and also made the decision to remove the
symfony/phpunit-bridge
dev dependency. This choice was influenced by the insights from the "PHPUnit 10 for Symfony Developers" talk presented at SymfonyCon Brussels/SymfonyOnline, which indicated that the bridge is no longer necessary for reporting deprecations.Our development involves a closed-source Symfony project for a client, and we've traditionally relied on the
symfony/phpunit-bridge
for deprecation reports. Specifically, we focus on identifying self and direct deprecations, such as instances where we call a method in oursrc
directory from a third-party library in thevendor
directory that will be removed in the next major version. This proactive approach helps us stay ahead during upgrades and the planning of our development tasks.Previous approach using
symfony/phpunit-bridge
With
symfony/phpunit-bridge
, distinguishing betweenself
,direct
, andindirect
deprecations was possible, see here and here. We utilized this to make tests fail onself
and especiallydirect
deprecations while "ignoring"indirect
deprecations, as they cannot directly be addressed by us.Current possibilites
With PHPUnit 10.5, it is already possible to get reports on deprecations using the following configuration (inspired by slide #66 from the conference's talk).
This will produce the following output when running tests that eventually trigger both direct and also indirect deprecations:
Feature request
With PHPUnit's added functionalities througout 10.X, nearly all the functionalities of
symfony/phpunit-bridge
can be replaced. However, regardless of where the deprecation is triggered, it is reported as a deprecation and will, if configured, fail the respective test.We propose adding the capability to distinguish whether a deprecation can be fixed by the project's maintainer (
self
&direct
deprecations) or if a project is unable to do so because the deprecated code is called internally by a third-party library from another third-party library (indirect
).A possible configuration option could look like this:
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="tests/bootstrap.php" + reportDeprecations="self,direct" displayDetailsOnTestsThatTriggerDeprecations="true" failOnDeprecation="true"> <!-- ... --> </phpunit>
Big thanks to everyone who's been part of improving PHPUnit! As we suggest this feature, fingers crossed we haven't missed a config trick or an ongoing discussion about it. If there's more we can share — examples, insights, you name it — we're glad to assist. Thanks! 🚀
The text was updated successfully, but these errors were encountered: