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

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

Closed
hemberger opened this issue Feb 10, 2023 · 3 comments
Closed

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

hemberger opened this issue Feb 10, 2023 · 3 comments
Assignees
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented
Milestone

Comments

@hemberger
Copy link

In PHPUnit 9, it was possible to get a non-zero exit code from phpunit if any tests encountered a warning, notice, or deprecation (with the proper configuration). This was very helpful for strictly prohibiting all error events.

I appreciate the distinction between test outcomes and test issues in PHPUnit 10, but I find myself missing the option for the process to return a non-zero exit code when there are any issues. This is still possible for warnings with failOnWarning, but it appears that no such option exists for notices or deprecations. Perhaps it would make sense to have boolean options failOnNotice and failOnDeprecation to fill this role? (This would also provide parity with the new displayDetailsOnTestsThatTrigger* options.)

If this functionality already exists, but I just missed it, my apologies! Thanks for all the work on PHPUnit 10. I'm very excited to start using it (especially for the code coverage color/css options, as a colorblind person).

@hemberger hemberger added the type/enhancement A new idea that should be implemented label Feb 10, 2023
@sebastianbergmann sebastianbergmann added the feature/test-runner CLI test runner label Feb 10, 2023
hemberger added a commit to hemberger/smr that referenced this issue Feb 10, 2023
The major functional changes from 9.5 to 10.0 are:

* Annotations are converted to attributes.
* Data providers must now be static.

Many data provider functions are converted to `TestWith` attributes.
These are safer now as attributes, because they can contain real PHP
objects (previously they had to be a JSON representation). When the
data sets are trivial, this is much simpler and more compact.

PHPUnit no longer returns non-zero exit code on notices/deprecations,
though they will still be printed in the results due to the use of the
`displayDetailsOnTestsThatTrigger*` settings. For more info, see:
sebastianbergmann/phpunit#5196

All tests are upgraded using the PHPUNIT_100 rector ruleset. It didn't
work perfectly, so some manual fixes were necessary.

Add custom CSS for phpunit HTML code coverage. This uses dark-mode and
colorblind-friendly colors.
hemberger added a commit to smrealms/smr that referenced this issue Feb 10, 2023
The major functional changes from 9.5 to 10.0 are:

* Annotations are converted to attributes.
* Data providers must now be static.

Many data provider functions are converted to `TestWith` attributes.
These are safer now as attributes, because they can contain real PHP
objects (previously they had to be a JSON representation). When the
data sets are trivial, this is much simpler and more compact.

PHPUnit no longer returns non-zero exit code on notices/deprecations,
though they will still be printed in the results due to the use of the
`displayDetailsOnTestsThatTrigger*` settings. For more info, see:
sebastianbergmann/phpunit#5196

All tests are upgraded using the PHPUNIT_100 rector ruleset. It didn't
work perfectly, so some manual fixes were necessary.

Add custom CSS for phpunit HTML code coverage. This uses dark-mode and
colorblind-friendly colors.
@stof
Copy link
Contributor

stof commented Feb 14, 2023

While I understand the logic for deprecations, I would still appreciate an option to fail on notices. A library that triggers notices when using it will often be considered bad as many frameworks turn notices into exceptions in dev mode.

@sebastianbergmann sebastianbergmann added this to the PHPUnit 10.1 milestone Feb 14, 2023
@sebastianbergmann sebastianbergmann self-assigned this Feb 14, 2023
@VincentLanglet
Copy link

In PHPUnit 9, the option convertDeprecationsToExceptions were failing only on deprecations

trigger_error('User Deprecation', \E_USER_DEPRECATED);

but not on

@trigger_error('User Deprecation', \E_USER_DEPRECATED);

Currently PHPUnit 10 consider both the same way

OK, but some tests have issues!
Tests: 1, Assertions: 4, Deprecations: 1.

So if we just add an option failOnDeprecation we won't get back the same behavior than the one in PHPUnit 9...

@sebastianbergmann
Copy link
Owner

So if we just add an option failOnDeprecation we won't get back the same behavior than the one in PHPUnit 9.

Please do not mix unrelated topics and post similar comments on different issues.

@sebastianbergmann sebastianbergmann changed the title Options to fail on notice/deprecation in PHPUnit 10 Optionally (fail|stop) on (notice|deprecation) events Mar 26, 2023
hemberger added a commit to hemberger/smr that referenced this issue Apr 22, 2023
This functionality was lost in PHPUnit 10.0, but was re-added via these
configuration options in PHPUnit 10.1.

See sebastianbergmann/phpunit#5196.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants