-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fixed PHPUnit 8.3 incompatibility: method handleError was renamed to __invoke #32890
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
Conversation
706ad67
to
0865fc4
Compare
@karser On |
True. Do we need this autoload juggling? Didn't we already define which ErrorHandler class to use on line 76?
|
0865fc4
to
4e9e3d7
Compare
@smoench Fixed. callPhpUnitErrorHandler is now static so it can be called from set_error_handler closure. |
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.
Tested and it solves issue. Thanks!
this is a critical blocker :( we need to completely redesign the way we hook there to collect deprecations. now we need to do this in our listener: when TestResult calls startTest in its run method, we need to register phpunit's error handler (duplicating what it does just after the call to startTest) and then add our collector. Then disable at endTest. Willing to dive there @karser? Maybe with help from @greg0ire too? Note that we need to do this for 3.4 and for 4.3 (since our code changed so much between the two) |
{ | ||
$ErrorHandler = self::$utilPrefix.'ErrorHandler'; | ||
if (self::$isHandlerInvokable) { | ||
$object = new $ErrorHandler($convertDeprecationsToExceptions = true, $convertErrorsToExceptions = true, $convertNoticesToExceptions = true, $convertWarningsToExceptions = true); |
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.
variables $convertDeprecationsToExceptions
, $convertErrorsToExceptions
are not used and should be omit
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.
It was done on purpose because (true, ture, true, true)
is not readable. FWIW @nicolas-grekas suggests to move this code to phpunit listener.
|
||
$handler = new self(); | ||
$oldErrorHandler = set_error_handler([$handler, 'handleError']); | ||
|
||
if (null !== $oldErrorHandler) { | ||
restore_error_handler(); | ||
|
||
if ([self::$utilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) { | ||
$handlerMethod = self::$isHandlerInvokable ? '__invoke' : 'handleError'; | ||
if ([self::$utilPrefix.'ErrorHandler', $handlerMethod] === $oldErrorHandler) { |
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.
if the previous handler is the PhpUnit one, then $oldErrorHandler
will contains an instance of PHPUnit\Util\ErrorHandler
@nicolas-grekas I'm not fully following what happens in phpunit bridge, so I'll ask some stupid questions:
|
it copes only with that responsbility yes
It looks like so. Currently, it doesn't need to be registered as a listener, but it looks like phpunit 8 changes that.
I'd say yes, one listener is easier to setup for users
yes, although it could be done in another PR if that's easier? |
@nicolas-grekas Ok, I'll try to do what you described, let's see how far I can get. |
Another alternative might be to check how As of now, I wouldn't recommend merging the PR, as putting all these settings at true is a bug that someone will report sooner than later. |
Maybe we can have a look at the stack trace and read the properties from there? It looks like we might find the |
TestResult is created by TestRunner which passes $arguments which contain the neccessary parameters. $arguments are created by TestRunner::handleConfiguration. Here is simpllified function which does exactly what we need:
|
c32c4a4
to
ede0976
Compare
ede0976
to
12717c9
Compare
I extracted this logic into ErrorHandlerCallerV83. It obtains the necessary variables the way PHPUnit does and instantiates ErrorHandler. I made sure that these variables are changed when I modify them in phpunit.xml. it works with both v8.2 and v8.3. |
Maybe in another PR to keep this one as is: could you please give a try to the stacktrace-based approach? I feel like it could be simpler and more robust. |
We should then call the previous handler if one was set, or return false |
Here is stacktrace-based PR #32933 |
The PHPUnit method handleError was renamed to __invoke in v8.3.
So we should check in Symfony DeprecationErrorHandler if method
handleError
exists, otherwise call__invoke
It works with phpunit v8.2.5 and 8.3.2.
The PHPUnit handler is called when I trigger some error, e.g
iconv('fdsfs', 'fsdfds', '');