-
-
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
Silenced E_USER_*
are ignored and triggers error/warning/notice/deprecation (display/failing)
#5325
Comments
Neither PHPUnit's MockBuilder nor any other part of PHPUnit acts on |
That's not true. The See:
|
Thank you so much for your persistence! I had totally forgotten about this arcane bit. |
You are welcome. We all know these kind of old code not having in mind and breaking someones neck. I'm not sure what would be really the solution - I'm open to come to a solution everyone is happy. However, I would suggest to revert the ignoring of the Sadly, in generall I would help more for another solution .. and we can discuss this. But in the open source project where I'm in the core team, I have quite some tasks to do for the upcoming LTS version beside a lot of stuff on my daytime job. So I have to switch back to the other project. Can we come somehow come together ? Special for the 10.1 release ? |
Basically, there are two ways to silence error levels: * set error_reporting to a value, not containing the error levels which should be silenced/not displayed * using the silence operator `@` to enforce silencing the error level, unrelated to the set error reporting level For example, it's possible that `E_ALL` has been set as global error_level() and therefore triggering a user deprecation/warning/error using the `trigger_error` method will be displayed. If the `@` silence operator is used before the `trigger_error()` call, the error is silenced. ```php error_reporting(E_ALL); trigger_error('', E_USER_DEPRECATED); // will be shown @trigger_error('', E_USER_DEPRECATED); // will not be shown ``` However, registered error handler will be called for all errors, despite it has been silenced or not for both possible ways to silence a error levels. ErrorHandler check the passed `$errorNumber` against the result of error_reporting() to determine if the errorNumber/errorLevel is supressed or not. That check will also detect a errorNumber as beeing silenced if the `@` silence operator has been used, which could and should be taken as a intentional and enforced silencing of an error (knowing that it would fail). There are multple use-cases, where for e.g. silenced user deprecation should not be taken as such, displayed and fail. MockBuilder converts `@deprecated` method docblock annotations to silenced `@trigger_error('', E_USER_DEPRECATED)` calls. Having a `@deprecated` annonation does not mean, that the original method call would trigger an `E_USER_DEPRECATED` error - and it's arguable that it should be a hard enforcement by PHPUnit to decide this and doing the conversion. Therefore, this change removes the possible silenceable error level list check from the `ErrorHander`. This restores how it has worked in PHPUnit v9 without opening follow up issues. This can be reintroduced, either in a configurable way or the same if related questions has been properly thought about and solved before: * MockBuilder @Deprecation -> trigger_error() configurable or removed * proper way to configure between own code / 3rd party code if silenced error levels should be stay silenced or not. This means not only in one direction. Related: #5325
Thanks! With this in place, we finished the migration to phpunit 10.1. We're happy phpunit can exit non-zero again in case a test calls a method that contains trigger_error('message', E_USER_DEPRECATED): |
Summary
Basically, there are two ways to silence error levels:
@
to enforce silencing the error level, unrelated to the set error reporting levelFor example, it's possible that
E_ALL
has been setas global error_level() and therefore triggering a
user deprecation/warning/error using the
trigger_error
method will be displayed. If the
@
silence operatoris used before the
trigger_error()
call, the erroris silenced.
However, registered error handler will be called for all errors, despite it has been silenced or not for both possible ways to silence a error levels. ErrorHandler check the
passed
$errorNumber
against the result of error_reporting() to determine if the errorNumber/errorLevel is supressed or not. That check will also detect a errorNumber as beeingsilenced if the
@
silence operator has been used, which could and should be taken as a intentional and enforced silencing of an error (knowing that it would fail).There are multple use-cases, where for e.g. silenced user deprecation should not be taken as such, displayed and fail.
MockBuilder converts
@deprecated
method docblock annotations to silenced@trigger_error('', E_USER_DEPRECATED)
calls. Having a@deprecated
annonation does not mean, that the original method call would trigger anE_USER_DEPRECATED
error - and it's arguable that it should be a hard enforcement by PHPUnit to decide this and doing the conversion.Using the
<source>
configuration does not help here to let silenced error levels in third party code be ignored but in own code triggerd - or own user errors ignored but 3rd party code ignored. Beside this, it's not possible to silence the silenced E_USER_DEPRECATION triggered by the converted@deprecected
annotations of mocked class methods.Current behavior
Silence state of
E_USER_*
errors are ignored, regardless if the have been silenced by PHP error level configuration or the@
silence operator before thetrigger_error()
call.PHPUnit v9 instead respectes enforced silenced user error levels.
How to reproduce
Using one of these calls in a class method:
Having a class:
and creating a mock of it:
triggers a suppressed
E_USER_DEPRECATED
error. The suppressing is ignored,and the deprecation is collected, displayed if selected and/or failing (exit
code > 0) if selected.
Expected behavior
And/or
As a intermediate solution ignoring a suppressed
E_USER_*
should be removed again, until a workable solution can be found to distingush with all containing parts. This reverts to how it has worked in PHPUnit v9.The text was updated successfully, but these errors were encountered: