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

[FEATURE] Make suppressed error levels for ErrorHandler configurable #5303

Closed
wants to merge 1 commit into from
Closed

[FEATURE] Make suppressed error levels for ErrorHandler configurable #5303

wants to merge 1 commit into from

Conversation

sbuerk
Copy link
Contributor

@sbuerk sbuerk commented Apr 8, 2023

PHPUnit v10 changed how it handles notices, warnings, errors and deprecations. Therefore, converting them to exception has been removed in favour of display/fail options per type. Recently, the last missing piece for notices and deprecation has been added with:

#5196: Optionally (fail|stop) on (notice|deprecation) events

PHPUnit v9 (and possibly earlier versions) did not converted suppressed error levels to exceptions, if the corresponded old and removed option has been set. With PHPUnit v10, only native PHP error level (notices/strict,warnings,deprecated) are not handled if suppressed using the "@" suppress operator or by error_reporting() configuration.

User error levels (notices,warnings,deprecation,error) are no longer suppressable.

It's impossible to have only one defined set, which should be suppressable AND suppressed state regonized to suite all needs for framework, packages and applications using PHPUnit to test things. This must be configurable for users of the PHPUnit.

This change adds configuration options to configure, which error levels are suppressable/suppressed state taking into account. Configuration is only provided through the PHPUnit configuration file. CLI options would not be really usefull, due "true" defauls - and therefore some options would be needed to be added "inverse". Having this only as XML options is more then suitable.

Added xml configuration file options for:

  • (bool) errorHandlerIgnoreSuppressedPhpDeprecations [default: true]
  • (bool) errorHandlerIgnoreSuppressedPhpNotices [default: true]
  • (bool) errorHandlerIgnoreSuppressedPhpWarnings [default: true]
  • (bool) errorHandlerIgnoreSuppressedUserDeprecations [default: false]
  • (bool) errorHandlerIgnoreSuppressedUserNotices [default: false]
  • (bool) errorHandlerIgnoreSuppressedUserWarnings [default: false]

NOTE ErrorLevels, which are configured to be ignored if
suppressed, will not fail with corresponding --fail-on-*
configuration/flag. On the other hand, this means that
if suppressed ignore is configured, it will fail even if
suppressed.

E_USER_ERROR, e.g. triggered by using trigger_error('', E_USER_ERROR), are not failing like php errors (E_ERROR). They always dispatches corresponding event. Additionally, there is no --fail-on-error flag which could control this for E_USER_ERROR. Therefore, E_USER_ERROR is left for now and should be targeted in a dedicated change.

Furthermore, a couple of tests are added to cover the new options.

Resolves #5302

sbuerk added a commit to sbuerk/phpunit-documentation-english that referenced this pull request Apr 8, 2023
This change adds the documentation for the recently added
configuration options:

* errorHandlerIgnoreSuppressedPhpDeprecations
* errorHandlerIgnoreSuppressedPhpNotices
* errorHandlerIgnoreSuppressedPhpWarnings
* errorHandlerIgnoreSuppressedUserDeprecations
* errorHandlerIgnoreSuppressedUserNotices
* errorHandlerIgnoreSuppressedUserWarnings

Related change sebastianbergmann/phpunit#5303
@sbuerk
Copy link
Contributor Author

sbuerk commented Apr 8, 2023

Prepared documentation part also in -> sebastianbergmann/phpunit-documentation-english#301

sbuerk added a commit to sbuerk/phpunit-documentation-english that referenced this pull request Apr 9, 2023
This change adds the documentation for the recently added
configuration options:

* errorHandlerIgnoreSuppressedPhpDeprecations
* errorHandlerIgnoreSuppressedPhpNotices
* errorHandlerIgnoreSuppressedPhpWarnings
* errorHandlerIgnoreSuppressedUserDeprecations
* errorHandlerIgnoreSuppressedUserNotices
* errorHandlerIgnoreSuppressedUserWarnings

Related change sebastianbergmann/phpunit#5303
PHPUnit v10 changed how it handles notices, warnings, errors and
deprecations. Therefore, converting them to exception has been
removed in favour of display/fail options per type. Recently, the
last missing piece for notices and deprecation has been added with:

  #5196: Optionally (fail|stop) on (notice|deprecation) events

PHPUnit v9 (and possibly earlier versions) did not converted
suppressed error levels to exceptions, if the corresponded old
and removed option has been set. With PHPUnit v10, only native
PHP error level (notices/strict,warnings,deprecated) are not
handled if suppressed using the "@" suppress operator or by
`error_reporting()` configuration.

User error levels (notices,warnings,deprecation,error) are no
longer suppressable.

It's impossible to have only one defined set, which should be
suppressable AND suppressed state regonized to suite all needs
for framework, packages and applications using PHPUnit to test
things. This **must** be configurable for users of the PHPUnit.

This change adds configuration options to configure, which
error levels are suppressable/suppressed state taking into
account. Configuration is only provided through the PHPUnit
configuration file. CLI options would not be really usefull,
due "true" defauls - and therefore some options would be
needed to be added "inverse". Having this only as XML options
is more then suitable.

Added xml configuration file options for:

* (bool) errorHandlerIgnoreSuppressedPhpDeprecations [default: true]
* (bool) errorHandlerIgnoreSuppressedPhpNotices [default: true]
* (bool) errorHandlerIgnoreSuppressedPhpWarnings [default: true]
* (bool) errorHandlerIgnoreSuppressedUserDeprecations [default: false]
* (bool) errorHandlerIgnoreSuppressedUserNotices [default: false]
* (bool) errorHandlerIgnoreSuppressedUserWarnings [default: false]

**NOTE** ErrorLevels, which are configured to be ignored if
         suppressed, will not fail with corresponding `--fail-on-*`
         configuration/flag. On the other hand, this means that
         if suppressed ignore is configured, it will fail even if
         suppressed.

E_USER_ERROR, e.g. triggered by using `trigger_error('', E_USER_ERROR)`,
are not failing like php errors (E_ERROR). They always dispatches
corresponding event. Additionally, there is no `--fail-on-error` flag
which could control this for E_USER_ERROR. Therefore, E_USER_ERROR
is left for now and should be targeted in a dedicated change.

Furthermore, a couple of tests are added to cover the new options.

Resolves #5302
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Merging #5303 (333e260) into main (f6fe684) will increase coverage by 0.08%.
The diff coverage is 98.78%.

@@             Coverage Diff              @@
##               main    #5303      +/-   ##
============================================
+ Coverage     84.80%   84.88%   +0.08%     
- Complexity     6030     6050      +20     
============================================
  Files           650      650              
  Lines         19132    19210      +78     
============================================
+ Hits          16224    16306      +82     
+ Misses         2908     2904       -4     
Impacted Files Coverage Δ
src/Runner/ErrorHandler.php 76.84% <95.00%> (+5.41%) ⬆️
src/TextUI/Configuration/Configuration.php 74.82% <100.00%> (+1.08%) ⬆️
src/TextUI/Configuration/Merger.php 90.31% <100.00%> (+0.23%) ⬆️
.../TextUI/Configuration/Xml/DefaultConfiguration.php 98.26% <100.00%> (+0.09%) ⬆️
src/TextUI/Configuration/Xml/Loader.php 96.63% <100.00%> (+0.03%) ⬆️
src/TextUI/Configuration/Xml/PHPUnit.php 96.17% <100.00%> (+0.41%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented status/waiting-for-feedback Waiting for feedback from original reporter feature/test-runner CLI test runner feature/events Issues related to PHPUnit's event system labels Apr 13, 2023
@sbuerk
Copy link
Contributor Author

sbuerk commented Apr 13, 2023

Sorry for the delay - was full with work and needed time to test with the mentioned options.

To be short, this pull-request does not make much sense IMO. So I would close it for now.

@sbuerk sbuerk closed this Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/events Issues related to PHPUnit's event system feature/test-runner CLI test runner status/waiting-for-feedback Waiting for feedback from original reporter type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurarable ErrorLevel supressing configuration for ErrorHandler
2 participants