Data Providers and Skipped Tests #6011
Labels
feature/data-provider
Data Providers
feature/test-runner
CLI test runner
type/enhancement
A new idea that should be implemented
PHPUnit 10.5 tightened up the data providers to flag as a error if a data provider returns an empty set. This causes problems in the case where the test the data provider feeds isn't something that is able to run in every situations where the tests are run. I'll use the example of a test of a feature that relies on a PHP module which may be absent.
If the module isn't there we know when we are generating the data provider records that we're just going to skip the test entirely. There really isn't much point in generating a long list of records just to skip the test dozens of times (along with needlessly spamming the output). This is much more of a problem if generating the data is time consuming or requires the absent module (for instance the module defines constants that are needed as part of the test data sets).
Previously we could do something like:
if (class_exists('module_class_name'))
{
return [];
}
and things would work out fine. Now the only option appears to be generate the dataset regardless (if that's even possible) or generate a dummy dataset when the test conditions aren't met. Which isn't exactly hard, but it's an ugly workaround.
If we don't want to allow empty data sets, some way of marking the data provider as "skipped" in the same way as we would mark a test as skipped would be useful to avoid dummy data we aren't going to do anything with.
something like
if (class_exists('module_class_name'))
{
self::markTestSkipped('Requires Module');
}
The text was updated successfully, but these errors were encountered: