Skip to content

Report a data provider that provides no data sets - #328

Open
SanderMuller wants to merge 1 commit into
phpstan:2.0.xfrom
SanderMuller:empty-data-provider
Open

Report a data provider that provides no data sets#328
SanderMuller wants to merge 1 commit into
phpstan:2.0.xfrom
SanderMuller:empty-data-provider

Conversation

@SanderMuller

@SanderMuller SanderMuller commented Sep 12, 2026

Copy link
Copy Markdown

EmptyDataProviderRule reports 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, like DataProviderDataRule. 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:

  • Generators are skipped. Whether a generator yields at all depends on control flow. Where it is decidable, core already reports deadCode.unreachable on the dead yield.
  • The phpstan-doctrine example in the issue is a generator guarded by PHP_VERSION_ID, which PHPStan models as int<70400, 80599>. No static check can decide it, and this rule does not report it.
  • A provider declared in another class is checked when that class is analysed, not from the test method.
  • With an undetectable PHPUnit version, DataProviderHelper does 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Empty data set provided by data provider"

1 participant