Adding helpers for asserting database query count
Description
Dealing with performance and scaling issues due to poorly designed code logic can cause a lot of hard to pin problems, especially in bigger projects. This PR adds some helpers to give the tools during development and in tests to check for hidden N+1 problems.
This PR adds the documentation for the functionality.
Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactor (refactoring a current feature, method, etc...)
- [ ] Code Coverage (adding/removing/updating/refactoring tests)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Remove feature (non-breaking change which removes functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Codecov Report
Attention: Patch coverage is 90.74074% with 5 lines in your changes missing coverage. Please review.
Project coverage is 5.13%. Comparing base (
7ef3525) to head (e84abef). Report is 21 commits behind head on 8.x.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| ...s/TestTraits/PhpUnit/TestDatabaseProfilerTrait.php | 90.74% | 5 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## 8.x #208 +/- ##
==========================================
+ Coverage 3.42% 5.13% +1.70%
- Complexity 659 677 +18
==========================================
Files 99 100 +1
Lines 2713 2767 +54
==========================================
+ Hits 93 142 +49
- Misses 2620 2625 +5
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@Mohammad-Alavi Any ideas how I can add tests for the trait?
@Mohammad-Alavi I have excluded the test traits from code coverage. I dont think it makes sense to specifically test test case helper traits.
@Mohammad-Alavi I have excluded the test traits from code coverage. I dont think it makes sense to specifically test test case helper traits.
@yalsicor I think the traits should be tested in the Core. The end user doesn't need to test them in their project but we have to test them here to make sure they are working as expected. I have included them in the coverage again. I am all ears if you think otherwise.
I have prepared the test file for your code to help you kickstart writing the tests for your new features. Everything else looks good to me :muscle: Add the tests and we are good to go. This would be a nice addition in oour testing toolset 💪 Thank you 😎
@Mohammad-Alavi I have added the tests and fixed some issues with my code.
I have removed the setUp method from the test class, since all of the methods are private methods and we dont have access to them on another class. The trait is added to the TestParent anyway, so we have access to the methods directly in the test class.
Let me know what you think.