Skip to content
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

Allow users to configure how deprecation warnings are triggered #4461

Closed
alexpott opened this issue Sep 22, 2020 · 3 comments
Closed

Allow users to configure how deprecation warnings are triggered #4461

alexpott opened this issue Sep 22, 2020 · 3 comments
Labels
type/enhancement A new idea that should be implemented

Comments

@alexpott
Copy link

At the moment PHPUnit deprecates code by calling TestCase::addWarning() for example

$this->addWarning('Support for using expectException() with PHPUnit\Framework\Error\Deprecated is deprecated and will be removed in PHPUnit 10. Use expectDeprecation() instead.');

Triggering these warnings is great because it helps people upgrade their code and get ready for the next version of PHPUnit. In Symfony-land deprecations are handled using @trigger_error('message', E_USER_DEPRECATED); - this allows the PHPUnit-Bridge component to manage deprecations triggered by code. It allows the projects to choose when they tackle the technical debt on their own terms. Drupal has also adopted this way of managed deprecated code.

It'd be great if there was a option in PHPUnit to trigger silenced deprecations instead of a warning. I propose that we add a TestCase::addDeprecation() method that depending on a flag in PHPUnit's configuration either calls TestCase::addWarning() or @trigger_error('message', E_USER_DEPRECATED);. The default should be to continue to use the warning system but then projects such as Drupal can set the flag to use their existing tools to manage how they cope with deprecations.

@alexpott alexpott added the type/enhancement A new idea that should be implemented label Sep 22, 2020
@helhum
Copy link
Contributor

helhum commented Oct 6, 2020

I would support that feature. If any of the options are supported, I'd be happy to create a PR for it

@sebastianbergmann
Copy link
Owner

It'd be great if there was a option in PHPUnit to trigger silenced deprecations instead of a warning.

My experience is: if something can be silenced, it will be silenced. And at the time when something is removed that was deprecated before and warned about the developers who silenced the warning will scream: we never saw this coming! So, no, I am against adding an option to silence these warnings.

@alexpott
Copy link
Author

alexpott commented Oct 7, 2020

@sebastianbergmann I can see how an option to ignore these errors might be too tempting. Good point. How about adding a method alongside addWarning() to add PHPUnit deprecations - something like addDeprecation so that project like Drupal can override this method to trigger a silenced deprecation. Note that using @trigger_error('message', E_USER_DEPRECATED); does not cause the deprecation to be silenced when running a test with Symfony's PHPUnitBridge - it causes the deprecation to be reported in a different way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

3 participants