-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the data provider for NodeScopeResolverTest #3163
Conversation
Instead of yielding resolved analysis for each data file, and then have the actual test only assert the given result, provide only the paths of the data files and have the actual analysis and assertion inside the test case. This brings the following benefits: 1) Listing tests and filtering by one single data file is much faster 2) Data files skipped due to php version requirement now show as skipped instead of silently disappearing. 3) If the analysis would fail, instead of busting the whole test suite due to an exception inside the data provider, it shows inside the test case.
I haven't gone into detail with the PR but please tell me if I'm right to assume that with this approach, the test will only tell us about first failure in any given file, right? Currently we're yielding all the asserts from a file to report errors on all of them at once. |
That is correct. But in a classic phpunit test file this is also the case:
The test bails at the first failed assertion. So you can think of the data file as a series of assertions, indeed only the first one failing is shown. |
Yes, this would be a huge downgrade from the current version. Your solution is faster by numbers "on paper" but in practice this would slow down our workflows too much. It's very valuable to see all errors at once. |
I suppose this can be done by refactoring further inside
Not really "on paper", when you are working on a particular data file don't you have to repeat it several times? Spending 1 second for each run instead of 30+ seems like a great benefit to me. |
I agree that seeing all errors per file is a big plus to get an idea of the impact of a change as a whole. |
Thank you for your contribution. I appreciate the time you invested in preparing this pull request. However, I have decided not to merge it. |
Instead of yielding resolved analysis for each data file, and then have the actual test only assert the given result, provide only the paths of the data files and have the actual analysis and assertion inside the test case. Rejected upstream as PR phpstan#3163
Instead of yielding resolved analysis for each data file, and then have the actual test only assert the given result, provide only the paths of the data files and have the actual analysis and assertion inside the test case. Rejected upstream as PR phpstan#3163
Refactor the data provider for NodeScopeResolverTest
Instead of yielding resolved analysis for each data file, and then have the
actual test only assert the given result, provide only the paths of the data
files and have the actual analysis and assertion inside the test case.
This brings the following benefits:
instead of silently disappearing (showcase 2).
debugging the actual source code (showcase 3).
an exception inside the data provider, it shows inside the test case (showcase 4).
I believe in particular the showcase 4 happened a lot of times and it's hard
to debug because phpunit does not properly show uncaught exceptions in the
data providers.
Showcase 1 - List available tests
Setup:
None.
Command:
time ./vendor/bin/phpunit --no-coverage tests/PHPStan/Analyser/NodeScopeResolverTest.php --list-tests
Before:
After:
Showcase 2 - Skipped data files due to version requirement now show up as skipped, same time
Setup:
None.
Command:
time ./vendor/bin/phpunit --no-coverage tests/PHPStan/Analyser/NodeScopeResolverTest.php --list-tests
Before:
After:
Showcase 3 - Running a single test data file with an assertion error, much faster
Setup:
Change
int<min, 2>
withint<min, 42>
ininteger-range-types.php
Command:
time ./vendor/bin/phpunit --no-coverage tests/PHPStan/Analyser/NodeScopeResolverTest.php --filter integer-range
Before:
After:
Showcase 4 - Running a single test data file with a SYNTAX error, faster and better reporting
Setup:
Change
, $i);
with, $i;
ininteger-range-types.php
Command:
time ./vendor/bin/phpunit --no-coverage tests/PHPStan/Analyser/NodeScopeResolverTest.php --filter integer-range
Before:
After: