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

Display deprecation stacktrace #5921

Closed
nikophil opened this issue Aug 8, 2024 · 7 comments · Fixed by #5923
Closed

Display deprecation stacktrace #5921

nikophil opened this issue Aug 8, 2024 · 7 comments · Fixed by #5923
Labels
type/enhancement A new idea that should be implemented

Comments

@nikophil
Copy link
Contributor

nikophil commented Aug 8, 2024

Hello,

sometimes finding where a deprecation comes from could be challenging. I think a mechanism in PHPUnit which displays the stack trace of deprecations would be helpful.

In Symfony, they've solved it by the following: if the SYMFONY_DEPRECATIONS_HELPER is a regex (I guess, they detect it if the var starts and ends with a /, or something like this), they break PHPUnit execution when the first deprecation resolving this regex is found, and the stack trace is printed.
see https://symfony.com/doc/current/components/phpunit_bridge.html#display-the-full-stack-trace

I'm not sure that breaking the execution is the best solution, but at least, it prevents for giant outputs if the test suite is full of deprecations.

I would be willing to contribute for this, but I'm not sure of how this should work. Do you see any other more elegant solution for this? Maybe we can add a new option which would display the stack traces, or at least write them in a file in order to not pollute the output?

thanks!

@nikophil nikophil added the type/enhancement A new idea that should be implemented label Aug 8, 2024
@soyuka
Copy link
Contributor

soyuka commented Aug 8, 2024

Indeed, we see that there's the first line of the stack trace, for example:

1) src/GraphQl/Type/SchemaBuilder.php:38
blabla

Triggered by:

* ApiPlatform\Tests\Functional\BackedEnumPropertyTest::testGraphQl
  Functional/BackedEnumPropertyTest.php:55

But when using the trigger_deprecation helper from Symfony, all you see is vendor/symfony/deprecation-contracts/function.php:25. Not sure how to fix that on the PHPUnit TextUI as it has no verbose mode.

I'm not a huge fan of the SYMFONY_DEPRECATIONS_HELPER flag it's complicated to program and isn't quite user-friendly.

@nikophil
Copy link
Contributor Author

nikophil commented Aug 8, 2024

maybe just a flag like --display-deprecation-with-stack would be enough

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Aug 9, 2024

Did you configure Symfony's trigger_deprecation() function as a deprecation trigger (see #5689 (comment) and https://docs.phpunit.de/en/11.3/configuration.html#the-deprecationtrigger-element) with PHPUnit?

@nikophil
Copy link
Contributor Author

nikophil commented Aug 9, 2024

nope, I didn't know about this configuration, and I think it will be the solution. Thanks!

what about to detect the existence of such triggers to automatically register the main known ones?

@nikophil
Copy link
Contributor Author

nikophil commented Aug 9, 2024

hum, it seems that it does not work as I expected: deprecationTriggers seems to be only involved in the decision whether the deprecation is self/direct/indirect.

Something nice, would be to use these trigger deprecation in order to display the real place where the deprecation was triggered.

meaning, instead of having this:

1 tests triggered 1 deprecation:

1) /app/vendor/symfony/deprecation-contracts/function.php:25
some deprecations

Triggered by:

* Tests\SomeTest::testSomething duration
  /app/tests/SomeTest.php:xx

it would display:

1 tests triggered 1 deprecation:

1) /app/vendor/path/to/real/deprecation.php:xx
some deprecations

Triggered by:

* Tests\SomeTest::testSomething duration
  /app/tests/SomeTest.php:xx

@sebastianbergmann
Copy link
Owner

Makes sense, I guess. Do you want to send a PR for this?

@nikophil
Copy link
Contributor Author

nikophil commented Aug 9, 2024

yes, let's do this :)

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

Successfully merging a pull request may close this issue.

3 participants