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

TestCase::onNotSuccessfulTest cannot mark tests as skipped or failed anymore in PHPUnit 10 #5202

Closed
stof opened this issue Feb 14, 2023 · 6 comments

Comments

@stof
Copy link
Contributor

stof commented Feb 14, 2023

Q A
PHPUnit version 10.0.7
PHP version 8.1.15
Installation Method Composer

Summary

In PHPUnit 9 and older, it was possible to override TestCase::onNotSuccessfulTest to change the outcome of a test, as this method was called before determining the test status based on the caught exception (and this method could throw a different one that would be used).
In PHPUnit 10, this method is called after determining the test status, which voids any use case I know for that extension point.

Examples of usage of that method:

Current behavior

How to reproduce

  1. Create a TestCase with a test throwing an exception
  2. Override the onNotSuccessfulTest method in that TestCase to call self::markTestSkipped() when that exception happened
  3. Run those tests both with PHPUnit 9 and 10 and compare the difference.

Expected behavior

@sebastianbergmann
Copy link
Owner

At least for me, there was only ever a single valid use case for this: to have an extension point to "do something" when a test fails. It was never meant to change the outcome of a test. So this is not a bug, it works as intended.

@stof
Copy link
Contributor Author

stof commented Feb 14, 2023

What would be the way to do what the driver testsuite does then ?

@stof
Copy link
Contributor Author

stof commented Feb 14, 2023

And as this is a behavior change for what is possible with onNotSuccessfulTest, it might make sense to document that in the changelog/upgrade guide for PHPUnit 10

@sebastianbergmann
Copy link
Owner

Already done in 7142280 :)

@sebastianbergmann sebastianbergmann removed the type/bug Something is broken label Feb 14, 2023
@stof
Copy link
Contributor Author

stof commented Feb 14, 2023

@sebastianbergmann do you think it is possible for PHPUnit 9.6 to report a deprecation for such usage ?

@sebastianbergmann
Copy link
Owner

I do not think so.

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

No branches or pull requests

2 participants