phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

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

Open stof opened this issue 1 month ago • 0 comments

When the data provider generates test cases based on some external sources, it might happen that there is no cases to be tested. As PHPUnit triggers an error when a data provider returns an empty iterable (technically when _all providers configured for a test do it, so that the merged result is empty, but most tests don't use multiple data providers), such projects end up doing hacks where the yield a single case in the data provider with special values that the test detects to call markTestSkipped.

Examples:

  • async-aws having a test enforcing that modified services include updates to their changelog (a PR might not modify any of the files requiring changelog entries): https://github.com/async-aws/aws/pull/1983
  • the IntegrationTestCase of Twig has a dedicated test running the "legacy" test cases, where deprecations are ignored. A project running Twig integration tests might not have any legacy tests: https://github.com/twigphp/Twig/blob/d58c8be15ddbda8532df7ba5de283b51dd8939d2/src/Test/IntegrationTestCase.php#L191

It would be great to have a way to opt-out of that error, marking the tests as skipped due to no provided data instead.

stof avatar Nov 07 '25 17:11 stof