-
-
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
Exceptions in data providers should be errors, not warnings #4483
Comments
Agreed. The 'unit' being tested is the code plus data. This is also how PHPUnit internally thinks as you might have noticed while digging around in the @sebastianbergmann is not-failing on brokken/incompatible data providers a way of working that is a leftover from earlier days, or is there a deeper reason behind it? For the lazy loading data providers I need to refactor the loading mechanism anyway. I don't see any big risks for converting the warning to a failure for either the current or future data loaders. |
Just discovered that the same behavior is true for mock objects, where e.g. when a class is final and can't be mocked the test will succeed with a warning but it didn't even run. That also doesn't seem sensible to me. New issue? |
It does not "succeed with a warning". A test is only successful when it is not marked as errored, failed, incomplete, skipped, risky -- and when there is no warning. By default, the PHPUnit test runner does not exit with an error code because of risky tests or tests that trigger warnings. However, the best practices configuration you get from <?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit> The |
I understand. What I think is conceptually problematic here is that two quite different things are classified as warnings:
Now a user has the choice: either fix all deprecation warnings immediately or risk false positives. Conceptually I think the better categorization of errors would be:
|
I agree that this should be changed, thank you for making a convincing argument. |
Thank you @sebastianbergmann |
Summary
When a data provider throws an exception, PHPUnit reports the error as a warning. This can lead to false positive test suite results where important tests are skipped but still the test suite succeeds when run without
failOnWarning=true
(which is the default).Current behavior
When a data providers throws a Throwable, it’s converted into a warning (from
PHPUnit\Framework\TestBuilder
)How to reproduce
Expected behavior
PHPUnit should issue an error instead.
The text was updated successfully, but these errors were encountered: