Skip to content

Add test for Unique validation rule with WhereIn constraints #55351

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

mohammadrasoulasghari
Copy link
Contributor

@mohammadrasoulasghari mohammadrasoulasghari commented Apr 10, 2025

Add tests for whereIn/whereNotIn with Unique validation 🧪

This PR adds tests for the whereIn and whereNotIn methods on the Unique validation rule that were previously untested. These tests ensure future changes to this user-facing feature won’t introduce unexpected side effects.
✅ Tests cover multiple validation scenarios

This commit adds proper database configuration for ValidationUniqueRuleTest class by:
1. Setting up an in-memory SQLite database
2. Creating the necessary 'users' table schema for testing
3. Adding connection helper methods for database operations
@mohammadrasoulasghari mohammadrasoulasghari marked this pull request as draft April 10, 2025 08:55
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

…ints

This commit adds a test that verifies the behavior of the Unique validation rule
when using both whereIn and whereNotIn constraints together. The test demonstrates
that:

1. The whereIn constraint limits validation to only consider records matching
   specified values ('admin', 'moderator', 'editor')
2. The whereNotIn constraint further excludes records with specific values ('editor')
   from validation
3. Records outside these constraints are ignored when checking uniqueness
4. Non-existent values are always considered unique
This commit refactors the `testItValidatesUniqueRuleWithWhereInAndWhereNotIn`
test to use the existing `EloquentModelStub` instead of a custom `User` model,
resolving name conflicts with other test files in the framework.
@mohammadrasoulasghari mohammadrasoulasghari marked this pull request as ready for review April 10, 2025 13:25
@mohammadrasoulasghari
Copy link
Contributor Author

mohammadrasoulasghari commented Apr 10, 2025

Also Added whereNot to testItCorrectlyFormatsAStringVersionOfTheRule as it was previously untested. This ensures all methods in the DatabaseRule trait are fully tested in the Unique validation class, leaving no validation scenarios uncovered.✅

@taylorotwell taylorotwell merged commit 437c460 into laravel:12.x Apr 10, 2025
58 checks passed
@mohammadrasoulasghari mohammadrasoulasghari deleted the feature/add-unique-rule-where-in-test branch April 10, 2025 15:18
mohammadrasoulasghari added a commit to mohammadrasoulasghari/laravel-framework that referenced this pull request Apr 17, 2025
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.

2 participants