Skip to content
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

Add Tests for Handling Null Primary Keys and Special Values in Unique Validation Rule #54823

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

alikhosravidev
Copy link
Contributor

This PR adds two test cases to the ValidationUniqueRuleTest class to handle edge cases in the Unique validation rule:

Null Primary Key in Ignored Models:

The test testItHandlesNullPrimaryKeyInIgnoreModel ensures the Unique rule correctly handles models with a null primary key when using the ignore method. This is important for newly created but unsaved models.
Special Values in where Clauses:

The test testItHandlesWhereWithSpecialValues checks how the where method handles special values like null, 0, and NOT_NULL in conditions. This ensures the correct formatting of these values in the validation rule string.

Why These Tests Are Important:

These tests cover edge cases (like null primary keys and special values) that can lead to unexpected behavior or bugs if not handled correctly.

Proper handling of these cases ensures that validation and database queries are consistent and reliable.

Expected Outcome:

The tests ensure that the Unique validation rule formats validation strings correctly when handling models with null primary keys and special values in where clauses.

This improves test coverage and reduces the likelihood of issues in production.

@taylorotwell taylorotwell merged commit a71794b into laravel:12.x Feb 27, 2025
41 checks passed
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