-
Notifications
You must be signed in to change notification settings - Fork 775
Add more benchmarks, smoke tests, make FilterVar serializable #1607
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1607 +/- ##
============================================
+ Coverage 97.51% 97.85% +0.34%
- Complexity 1006 1007 +1
============================================
Files 212 212
Lines 2334 2335 +1
============================================
+ Hits 2276 2285 +9
+ Misses 58 50 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances testing infrastructure by consolidating validator test data into a reusable trait, adding comprehensive benchmarks, and making the FilterVar validator serializable.
Changes:
- Introduced
SmokeTestProvidertrait with comprehensive validator test data for reuse across benchmarks and serialization tests - Added serialization test coverage to verify validators can be serialized and deserialized
- Refactored
FilterVarfrom extendingEnvelopeto directly implementingValidatorto support serialization
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/library/SmokeTestProvider.php | New trait providing test data for all validators, enabling reuse across different test types |
| tests/unit/SerializableTest.php | New test verifying validators can be serialized/unserialized while maintaining functionality |
| tests/benchmark/ValidatorBench.php | Refactored to use SmokeTestProvider, expanding benchmark coverage from ~50 to ~150 validators |
| phpbench.json.dist | Updated bootstrap path to use tests/bootstrap.php for proper test environment setup |
| library/Validators/FilterVar.php | Refactored to implement Validator directly instead of extending Envelope for serialization support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I would be great if you could add the information you have in the pull request to the commit message, it helps with adding more context when looking at the git logs. Personally, I prefer when the commit tells what it does in the subject line, and explain why in the body. This subject line tells 3 different things, and it would be best to have a subject line that expresses (in imperative mood) the overarching subject of the commit. |
henriquemoody
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments are mostly cosmetic, but the place where that test is, I think we should really change.
| public function evaluate(mixed $input): Result | ||
| { | ||
| return Result::of( | ||
| (self::ALLOWED_FILTERS[$this->filter])(match ($this->options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is match the new ternary? 😂
Not asking to change, I just thought it was an interesting way to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our combination of static analyzers doesn't allow multi-line ternaries, which I do in fact prefer, like this:
$isSomething
? whenTrue()
: whenFalse()It forces them to be inline, and then the line becomes too big for the line length rule. In this case, it doesn't justify creating methods to wrap the conditions.
A match circumvents that, and I used it as a hack definitely! It will lead to the same opcodes as a ternary though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not criticising, I genuinely found it interesting, and I can see the benefits
| use SmokeTestProvider; | ||
|
|
||
| #[DataProvider('provideValidatorInput')] | ||
| public function testValidatorSerialization(Validator $v, mixed $input): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public function testValidatorSerialization(Validator $v, mixed $input): void | |
| [#Test] | |
| public function validatorSerialization(Validator $v, mixed $input): void |
I wish there was a rule for that in PHP_CodeSniffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might not even need to change that if we turn that into a feature test.
| '{{subject}} must not be valid', | ||
| )] | ||
| final class FilterVar extends Envelope | ||
| final class FilterVar implements Validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| final class FilterVar implements Validator | |
| final readonly class FilterVar implements Validator |
We can make it readonly now. I will look for a PHP_CodeSniffer rule that does that when possible.
| use function unserialize; | ||
|
|
||
| #[Group('core')] | ||
| final class SerializableTest extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a unit test, and although it's arguable not a feature test either, it's best to put it there, maybe turn into a Pest test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I reuse the data provider in the Pest test cleanly? If you know how to do it, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Datasets: https://pestphp.com/docs/datasets, maybe an extra array_map() around it, but about that
This improves
composer benchby adding a lot of new benchmarks.The provider for benchmarks is now available as a generic smoke test provider that can be used when we want to test aspects of all validators. For example, serialize compatibility. A test for serialize compatibility was also introduced.
There are still a few validators that are not serializable.
Image,MimetypeandUploaded, mostly. Since those have some sort of similarity, they will be addressed later.