Skip to content

Optional $skipWhenEmpty parameter for #[DataProvider] and #[DataProviderExternal]#6565

Draft
sebastianbergmann wants to merge 1 commit intomainfrom
issue-6404/data-provider-opt-in-empty-data-set
Draft

Optional $skipWhenEmpty parameter for #[DataProvider] and #[DataProviderExternal]#6565
sebastianbergmann wants to merge 1 commit intomainfrom
issue-6404/data-provider-opt-in-empty-data-set

Conversation

@sebastianbergmann
Copy link
Copy Markdown
Owner

@sebastianbergmann sebastianbergmann commented Apr 5, 2026

This implements an optional $skipWhenEmpty parameter (defaulting to false) for the #[DataProvider] and #[DataProviderExternal] attributes. When set to true, a data provider that returns an empty iterable will cause the test to be skipped instead of triggering an error.

Usage:

#[DataProvider('provider', skipWhenEmpty: true)]
public function testSomething(string $value): void
{
    // ...
}

Note: Parameter names are not covered by the backward compatibility promise for PHPUnit.

When all data providers for a test method return no data and at least one of them has skipWhenEmpty: true, the test is created as a single test case that skips itself with the message "The data provider for this test provided no data, which is explicitly permitted". The default behavior (error on empty data provider) is unchanged.

Closes #6404.

@sebastianbergmann
Copy link
Copy Markdown
Owner Author

@stof Is this what you had in mind?

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.91%. Comparing base (043a636) to head (5fe6f25).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6565   +/-   ##
=========================================
  Coverage     96.90%   96.91%           
- Complexity     7604     7613    +9     
=========================================
  Files           819      819           
  Lines         23512    23533   +21     
=========================================
+ Hits          22785    22806   +21     
  Misses          727      727           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/data-provider Data Providers feature/metadata/attributes type/enhancement A new idea that should be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add (opt-in?) support for data providers returning an empty iterable

1 participant