Report a data provider that provides no data sets - #328
Open
SanderMuller wants to merge 1 commit into
Open
Conversation
PHPUnit 10 and newer rejects a data provider that provides nothing. PHPUnit 9 skipped the test instead. EmptyDataProviderRule reports a provider method whose every return statement returns an iterable that is provably empty. It skips generators, because whether a generator yields at all depends on control flow the rule cannot decide. Closes phpstan#251 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EmptyDataProviderRulereports a data provider method whose every return statement returns an iterable that is provably empty. PHPUnit 10 and newer errors on this. PHPUnit 9 skipped the test.Registered behind
bleedingEdge, likeDataProviderDataRule. It reports unless the detected PHPUnit major is 9 or lower, so a project where the version cannot be detected still gets the check.Scope limits, each deliberate:
deadCode.unreachableon the deadyield.phpstan-doctrineexample in the issue is a generator guarded byPHP_VERSION_ID, which PHPStan models asint<70400, 80599>. No static check can decide it, and this rule does not report it.DataProviderHelperdoes not read#[DataProvider], so only annotation-declared providers are covered. That is existing helper behaviour, and the test encodes it.Infection on the changed lines generates 3 mutants. All 3 are killed by the test framework, at 100% covered MSI.
Closes #251