Behat icon indicating copy to clipboard operation
Behat copied to clipboard

[RFC] Use deprecation contracts to notice developers about future deprecations

Open fmatsos opened this issue 1 year ago • 7 comments

As we will drop support for annotations to PHP attributes in the near future, I thought it might be useful to start displaying deprecation notices to prepare users for the migration.

For this I suggest using the package symfony/deprecation-contracts, which provides a single global function trigger_deprecation that triggers silenced deprecation notices.

This could also be used for any other planned deprecations in the code and/or features.

fmatsos avatar Dec 19 '24 15:12 fmatsos

The actual need is for Behat is to build a reporter for deprecations. Making it compatible with the deprecations triggered in symfony/deprecation-contracts is indeed a good idea, given that many projects are using this way of reporting deprecations (Symfony of course, but also Drupal for instance), either through symfony/deprecation-contracts or using trigger_error(..., E_USER_DEPRECATED) directly. doctrine/deprecations can also be configured to use the same reporting mechanism.

However, symfony/deprecation-contracts won't help us implement the reporter (if Behat itself does not need to trigger deprecations, it won't even need to have symfony/deprecation-contracts as a dependency).

stof avatar Jan 31 '25 10:01 stof

Is there any specification about the reporter needs? I'm not sure to understand what you mean exactly.

fmatsos avatar Mar 05 '25 16:03 fmatsos

@fmatsos I believe that @stof means we need a new feature for Behat to collect details of deprecations during a run and report them separately from failures & exceptions. We'd probably want a way for end-users to configure whether deprecations should cause the suite to fail or not. I'd expect this to be similar to the way PHPUnit handles this.

We'd also need to work out the best way to make this BC with the existing defaults / options for customising the errorlevel in the behat process.

I was thinking of having a go at this when I get a chance, but if you would like to / have time to look at it that would be great and I'd be happy to talk more about how it could work :)

acoulton avatar Mar 10 '25 20:03 acoulton

@stof Do you want to report all deprecations or only behat's one ?

FWIW, I use https://github.com/caciobanu/behat-deprecation-extension that report all deprecations after the run.

It's a good idea, but it's quite annoying as there might be a lot of deprecations where the user can't do anything:

App → package A → package B

If package B trigger a deprecation, then iti's logged, but the app can't do anything about it, as it needs to be taken care of in package A.

jdeniau avatar Sep 10 '25 20:09 jdeniau

the idea is to report all deprecations happening during the run (potentially configurable to allow distinguishing direct vs indirect deprecations as done in phpunit and symfony/phpunit-bridge)

stof avatar Sep 11 '25 07:09 stof

OK So caciobanu/behat-deprecation-extension does that as an extension if this is not implemented in behat.

jdeniau avatar Sep 11 '25 07:09 jdeniau

@jdeniau thanks for the pointer - that's useful to know, I wasn't aware of that. I think it would be good to have this as a core Behat feature in future, but in the meantime that looks like a very helpful extension.

acoulton avatar Sep 11 '25 09:09 acoulton