Skip to content

Skip data provider build when requirements are not satisfied#5957

Merged
sebastianbergmann merged 2 commits intosebastianbergmann:10.5from
MauricioFauth:data-provider-requires-phpunit
Sep 27, 2024
Merged

Skip data provider build when requirements are not satisfied#5957
sebastianbergmann merged 2 commits intosebastianbergmann:10.5from
MauricioFauth:data-provider-requires-phpunit

Conversation

@MauricioFauth
Copy link
Copy Markdown
Contributor

There is no reason to build the data provider if the test will be skipped anyway.

This also makes it easier to support a wide range of PHPUnit versions, as a data provider method that is incompatible with newer PHPUnit versions will not cause an error.

@MauricioFauth MauricioFauth force-pushed the data-provider-requires-phpunit branch 2 times, most recently from 039cc5c to f872c06 Compare September 19, 2024 18:24
Comment thread tests/end-to-end/generic/invalid-requirements.phpt
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.14%. Comparing base (7ac8b4e) to head (29dc63d).
Report is 8 commits behind head on 10.5.

Additional details and impacted files
@@            Coverage Diff            @@
##               10.5    #5957   +/-   ##
=========================================
  Coverage     94.14%   94.14%           
- Complexity     6446     6447    +1     
=========================================
  Files           678      678           
  Lines         19455    19455           
=========================================
  Hits          18316    18316           
  Misses         1139     1139           

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

Comment thread tests/_files/DataProviderRequiresPhpUnitTest.php
);
$data = null;

if ((new Requirements)->requirementsNotSatisfiedFor($className, $methodName) === []) {
Copy link
Copy Markdown
Contributor

@staabm staabm Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether it would make sense to not build the whole test and e.g. return early (or handle this case further up the call chain), in case requirements will not be satisfied

atm this only prevents building the dataprovider

Copy link
Copy Markdown
Contributor

@mvorisek mvorisek Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and would probably solve #4391 as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to skip the test here, because the data provider build happens earlier when building the test suite, since a test with a data provider is a test suite itself. What this fix does is ignore the data provider and treat the test as a single test, and not a test suite.

The test will be skipped later when running the test suite. Creating a separate process happens just before running the test, but after the test suite build.

@MauricioFauth MauricioFauth force-pushed the data-provider-requires-phpunit branch from 961ef5a to 29dc63d Compare September 25, 2024 18:37
@sebastianbergmann sebastianbergmann merged commit 922e4d8 into sebastianbergmann:10.5 Sep 27, 2024
@staabm
Copy link
Copy Markdown
Contributor

staabm commented Sep 27, 2024

btw: we recently reworked some of our testing in PHPStan because some data-provider building was super slow, as we did a lot of stuff there.

having them only built when the tests really ran, might have a positive perf impact.

(just wanted to leave another argument why this PR is a good thing)

@MauricioFauth MauricioFauth deleted the data-provider-requires-phpunit branch September 27, 2024 10:37
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants