-
-
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
Fix error handler to not silence error_get_last()
result
#5592
Fix error handler to not silence error_get_last()
result
#5592
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 10.5 #5592 +/- ##
============================================
+ Coverage 89.00% 89.01% +0.01%
+ Complexity 6363 6362 -1
============================================
Files 673 673
Lines 20293 20294 +1
============================================
+ Hits 18061 18065 +4
+ Misses 2232 2229 -3 ☔ View full report in Codecov by Sentry. |
0a28bd2
to
6cc6dad
Compare
This will not go into a minor version such as PHPUnit 10.5. Please target |
6cc6dad
to
b67a9dc
Compare
@jrfnl What do you think? |
This still targets the |
Based on #5592 (comment) I was/am waiting for @jrfnl response. I would be happy if this fix could land into 10.x. In 9.x and lower, there was no error handler with The original fix landed in 10.3 requires The changed LOC is minimal, most of the changed/added LOC are because of added tests. As there is no BC break and it is a bugfix, is there any reason to not land it into 10.x? |
Maybe I am wrong, but this change feels "too big" for me to land in a bugfix release. I will need to think about this. |
b67a9dc
to
7dfa49b
Compare
Rebase fixed to account for #5599 changes. |
041a32c
to
b424341
Compare
error_get_last()
result
PHPUnit has changed the behavior of the error handler in several ways, for example introducing a PHP attribute to disable the PHPUnit error handler for tests dealing with `error_get_last()` [1], throwing an exception and stopping the script execution on `E_*_ERROR` or clearing the error result [2] - which breaks the ability to use the native `error_get_last()` method to test custom error handler implementation. Something which TYPO3 needs to do for the provided custom error handler. An additional change [3] to check and restore error handlers with levels has been reverted due to issues in the Laravel world. This change modifies the related test to use the introduced PHP attribute `#[WithoutErrorHandler]` and raises PHPUnit. Note: PHPUnit does not recognize the `@test` doc-block annotation if the `#[WithoutErrorHandler]` attribute is used. Therefore, the attribute counterparts for `@test` and `@dataProvider` has been added on top and not exclusively for now, albeit looking weird and fishy. This needs to be addressed in a more generic way in a dedicated change. Used command(s): > composer update typo3/testing-framework > composer require --dev "phpunit/phpunit":"^10.5.5" [1] sebastianbergmann/phpunit#5430 [2] sebastianbergmann/phpunit#5592 [3] sebastianbergmann/phpunit#5619 Resolves: #102724 Releases: main, 12.4 Change-Id: I77f750ef2eba53b5f8caa51651f36321ae5d1224 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82282 Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
PHPUnit has changed the behavior of the error handler in several ways, for example introducing a PHP attribute to disable the PHPUnit error handler for tests dealing with `error_get_last()` [1], throwing an exception and stopping the script execution on `E_*_ERROR` or clearing the error result [2] - which breaks the ability to use the native `error_get_last()` method to test custom error handler implementation. Something which TYPO3 needs to do for the provided custom error handler. An additional change [3] to check and restore error handlers with levels has been reverted due to issues in the Laravel world. This change modifies the related test to use the introduced PHP attribute `#[WithoutErrorHandler]` and raises PHPUnit. Note: PHPUnit does not recognize the `@test` doc-block annotation if the `#[WithoutErrorHandler]` attribute is used. Therefore, the attribute counterparts for `@test` and `@dataProvider` has been added on top and not exclusively for now, albeit looking weird and fishy. This needs to be addressed in a more generic way in a dedicated change. Used command(s): > composer require --dev \ "phpunit/phpunit":"^10.5.5" \ "typo3/testing-framework":"^8.0.8" [1] sebastianbergmann/phpunit#5430 [2] sebastianbergmann/phpunit#5592 [3] sebastianbergmann/phpunit#5619 Resolves: #102724 Releases: main, 12.4 Change-Id: I77f750ef2eba53b5f8caa51651f36321ae5d1224 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82283 Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
PHPUnit has changed the behavior of the error handler in several ways, for example introducing a PHP attribute to disable the PHPUnit error handler for tests dealing with `error_get_last()` [1], throwing an exception and stopping the script execution on `E_*_ERROR` or clearing the error result [2] - which breaks the ability to use the native `error_get_last()` method to test custom error handler implementation. Something which TYPO3 needs to do for the provided custom error handler. An additional change [3] to check and restore error handlers with levels has been reverted due to issues in the Laravel world. This change modifies the related test to use the introduced PHP attribute `#[WithoutErrorHandler]` and raises PHPUnit. Note: PHPUnit does not recognize the `@test` doc-block annotation if the `#[WithoutErrorHandler]` attribute is used. Therefore, the attribute counterparts for `@test` and `@dataProvider` has been added on top and not exclusively for now, albeit looking weird and fishy. This needs to be addressed in a more generic way in a dedicated change. Used command(s): > composer update typo3/testing-framework > composer require --dev "phpunit/phpunit":"^10.5.5" [1] sebastianbergmann/phpunit#5430 [2] sebastianbergmann/phpunit#5592 [3] sebastianbergmann/phpunit#5619 Resolves: #102724 Releases: main, 12.4 Change-Id: I77f750ef2eba53b5f8caa51651f36321ae5d1224 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82282 Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
PHPUnit has changed the behavior of the error handler in several ways, for example introducing a PHP attribute to disable the PHPUnit error handler for tests dealing with `error_get_last()` [1], throwing an exception and stopping the script execution on `E_*_ERROR` or clearing the error result [2] - which breaks the ability to use the native `error_get_last()` method to test custom error handler implementation. Something which TYPO3 needs to do for the provided custom error handler. An additional change [3] to check and restore error handlers with levels has been reverted due to issues in the Laravel world. This change modifies the related test to use the introduced PHP attribute `#[WithoutErrorHandler]` and raises PHPUnit. Note: PHPUnit does not recognize the `@test` doc-block annotation if the `#[WithoutErrorHandler]` attribute is used. Therefore, the attribute counterparts for `@test` and `@dataProvider` has been added on top and not exclusively for now, albeit looking weird and fishy. This needs to be addressed in a more generic way in a dedicated change. Used command(s): > composer require --dev \ "phpunit/phpunit":"^10.5.5" \ "typo3/testing-framework":"^8.0.8" [1] sebastianbergmann/phpunit#5430 [2] sebastianbergmann/phpunit#5592 [3] sebastianbergmann/phpunit#5619 Resolves: #102724 Releases: main, 12.4 Change-Id: I77f750ef2eba53b5f8caa51651f36321ae5d1224 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82283 Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Hi @sebastianbergmann @mvorisek. It seems this PR breaks Lumen's test suite: https://github.com/laravel/lumen-framework/actions/runs/7373447479/job/20062657751 Details
I can confirm the changes in this PR cause this because if I revert them locally, tests pass again. At this time I can't provide a way to reproduce or exactly pinpoint why this PR causes the tests to fail as I'm too unfamiliar with PHPUnit's internals. @sebastianbergmann would you maybe consider reverting this PR in a similar fashion as was done with #5619 ? |
@driesvints Yes, I would consider that. I am travelling for the next two weeks and will only be able to work on and off. Therefore, it would help me a lot to get this done quickly if you could send a pull request for |
Reverting this will cause issues for users relying on this bugfix. @driesvints please provide a minimal repro as a testcase and I can look into it. |
@sebastianbergmann Thank you, we appreciate that! I've sent in the PR here: #5637
I don't know how sorry. |
Isolate https://github.com/laravel/lumen-framework/blob/v10.0.2/tests/HandleExceptionsTest.php#L119 test into a repro repository with minimal deps/sources. The issue is probably in https://github.com/laravel/lumen-framework/blob/v10.0.2/src/Concerns/RegistersExceptionHandlers.php#L73 as it relies on specific Or consider changing your code to always handle errors no matter what the Because of this, I ask you to retract #5637 as it will break other users relying on this bugfix. |
I'm sorry but I don't understand why we should change our code. This has worked perfectly fine for us for years with using PHPUnit. If PHPUnit were to change this in a new major version we'd could look into adopting the new way of doing things. But right now I feel this is a breaking change, sorry. |
@driesvints see the two issues in this PR description, there was big breaking change introduced in PHPUnit 10.0.0 and this PR fixes it - your code relies on specific The reason is we MUST NOT HANDLE the php warnings but instead LOG them only. This is what this PR does. To prevent php printing the unhandled php warnings, the |
…which makes tests fail
…which makes tests fail
fix #5587 (and older #5428)
The updated PHPUnit error handler still supresses the output and still logs the errors as before.
This PR implies no BC break for existing PHPUnit 10.x tests /w and /wo
WithoutErrorHandler
attribute.The
WithoutErrorHandler
attribute should be deprecated in the next minor version, as the new error handler impl. does not effectively imply any side effects so the behaviour /w and /wo PHPUnit error handler enabled is newly the same. In the next major version, the attribute should be completely removed and related c2c8dbb and e676667 commits reverted.In addition to fixing the linked issues:
error_clear_last()
is called before every test to clearerror_get_last()
E_USER_ERROR
aborts script execution by default, so newly the updated PHPUnit error handled does the same