-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Ignore Pest Files when finding and loading Classes #219
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## main #219 +/- ##
============================================
- Coverage 95.47% 95.47% -0.01%
- Complexity 259 266 +7
============================================
Files 44 44
Lines 752 774 +22
============================================
+ Hits 718 739 +21
- Misses 34 35 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is an attempt to solve compatibility issues when the laravel-stats package is run in a project that uses PestPHP.
Due to the nature of how laravel-stats currently works, we can't easily provide support for Pest Tests. (
stats
searches for PHP Classes in your project and groups them into Components. Pest Tests are PHP files containing functions.)This PR attempts to solve the compatibility issue, by checking the contents of a PHP file, before requiring it.
If the file contains "test" or "Test" and uses one of the prominent Pest PHP methods like
test()
,it()
,describe()
orbeforeEach()
, we consider it a Pest PHP file and exclude it from being required.(Might be a too naive approach, but I can't think of anything better right now.)
More Technical Notes
When users run
php artisan stats
in a project that uses Pest, they are immediately greeted with the following error message.This happens as
stats
immediately starts looking for files in a project and requiring them in theClassesFinder
-class.When a Pest file is required, the
test()
orit()
method seems to be immediately triggered or executed, which in turn will execute the following line in Pest that runsTestSuite::getInstance()
.https://github.com/pestphp/pest/blob/f1414a0beb43da066cf33276e22ea1209f047667/src/Functions.php#L121
As Pest is not triggered in a test environment the InvalidPestCommand exception is thrown.
Related Issues
TODOs