Skip to content

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

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 22, 2023

Fix PHPORM-68

Missed in d5f1bb9.

@GromNaN GromNaN force-pushed the presence-verifier branch from 1a59835 to 0213ce3 Compare August 22, 2023 09:14
@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (e7d4034) 90.59% compared to head (07e13a4) 90.60%.

❗ 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              
Files Changed Coverage Δ
src/Validation/DatabasePresenceVerifier.php 80.00% <100.00%> (+3.07%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

// Generates a regex like '/^(a|b|c)$/i' which can query multiple values
$regex = new Regex('^('.implode('|', $values).')$', 'i');
Copy link
Member

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?

Copy link
Member Author

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.

@GromNaN GromNaN force-pushed the presence-verifier branch from 0213ce3 to 07e13a4 Compare August 22, 2023 20:19
@GromNaN GromNaN requested a review from alcaeus August 23, 2023 09:25
Copy link
Member

@alcaeus alcaeus left a 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');
Copy link
Member

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());
Copy link
Member

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?

Copy link
Member Author

@GromNaN GromNaN Aug 23, 2023

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.

@alcaeus alcaeus merged commit af13eda into mongodb:master Aug 23, 2023
@GromNaN GromNaN deleted the presence-verifier branch August 23, 2023 11:00
@GromNaN GromNaN added this to the 4.0.0 milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants