-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PHPORM-68 Fix partial value un exist validator #2568
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
Conversation
1a59835
to
0213ce3
Compare
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## master #2568 +/- ##
============================================
+ Coverage 90.59% 90.60% +0.01%
- Complexity 749 750 +1
============================================
Files 34 34
Lines 1787 1789 +2
============================================
+ Hits 1619 1621 +2
Misses 168 168
☔ View full report in Codecov by Sentry. |
} | ||
|
||
// Generates a regex like '/^(a|b|c)$/i' which can query multiple values | ||
$regex = new Regex('^('.implode('|', $values).')$', 'i'); |
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.
I'm aware it wasn't done before, but shouldn't each individual value be sent through preg_quote
?
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.
Indeed they should. I'll add tests also.
0213ce3
to
07e13a4
Compare
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.
LGTM if my assumption about $validator->fails()
is correct.
} | ||
|
||
// Generates a regex like '/^(a|b|c)$/i' which can query multiple values | ||
$regex = new Regex('^('.implode('|', array_map(preg_quote(...), $values)).')$', 'i'); |
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.
The first-class callable syntax is just beautiful...
['name' => ['test name', 'john']], // Part of an existing value | ||
['name' => 'required|exists:users'] | ||
); | ||
$this->assertTrue($validator->fails()); |
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.
Just to confirm, $validator->fails()
is expected to return true
here because we're checking that a user with that exact name exists?
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.
Yes, according to the previous tests, the validation must fail when the value is NOT found in the collection.
Fix PHPORM-68
Missed in d5f1bb9.