-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
collect autoloading deprecations before running testCase #6165
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
base: main
Are you sure you want to change the base?
Conversation
src/TextUI/Application.php
Outdated
@@ -178,8 +178,16 @@ public function run(array $argv): int | |||
|
|||
EventFacade::instance()->seal(); | |||
|
|||
$depreciations = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this variable should be $deprecations
.
src/Runner/ErrorHandler.php
Outdated
@@ -422,4 +424,16 @@ private function stackTrace(): string | |||
|
|||
return $buffer; | |||
} | |||
|
|||
public function collectGlobalDepreciations(array $deprecations): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this method should be collectGlobalDeprecations
.
I think this idea is worthwhile to pursue. Please fix the existing tests and add new tests to cover the changed/added functionality. I do not consider this to be a bug fix, so this pull request should target the |
d02f1ab
to
10515dd
Compare
#5844 linkI updated the code, interestingly this conflicts with the resolution of #5844 (https://github.com./sebastianbergmann/phpunit/commit/8e8776083c71277fa90403b183530c956b110b60). To mitigate this I need to use something like:phpunit/src/Framework/TestCase.php Lines 1598 to 1610 in dd3bb4b
The idea would be to restore only the handler that we set to avoid restoring another handler registered by third party (bootstrap or test suite configuration). The handler that's created in the |
3a94e60
to
af0dc23
Compare
@@ -0,0 +1,12 @@ | |||
<?php declare(strict_types=1); | |||
|
|||
spl_autoload_register(function ($class) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reflects what happens when loading classes usually, if we do the same as in #5844 we'll trigger the deprecation during the loadBootstrapScript
.
83dcd44
to
987f371
Compare
Did you test this with OPcache? I came across this PR on my phone and php/php-src#17422 sounds relevant. |
I don't use opcache |
1bb9097
to
5af6639
Compare
When one triggers a deprecation in a class directly like this:
This technique is notably used in many Symfony components, for example:
https://github.com./symfony/symfony/blob/82cf90aefb7e9117ebd981fec83d7546e310e52b/src/Symfony/Component/PropertyInfo/Type.php#L12-L15
The deprecation will be triggered when autoloading the class, which happens in:
phpunit/src/TextUI/Application.php
Line 181 in 4b6a4ee
At that point, the ErrorHandler is not registered and we loose the deprecation.
This pull request gives an idea on how it may be fixed, indeed the
ErrorHandler
needs aTestCase
therefore I'm collecting these deprecations and triggering them once we callErrorHandler::enable
. I'm open to suggestions on how to fix this differently. Obviously I'll add tests if/once a solution is found that can be merged.Thanks!