-
Notifications
You must be signed in to change notification settings - Fork 0
Adjust all type-specific/rule-dedicated methods to check only their own validation rule #40
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
Open
Neluxx
wants to merge
17
commits into
cakephp-5.x
Choose a base branch
from
38-check-only-own-validation-rule
base: cakephp-5.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ae328b9
Check only own validation rule
Neluxx e4fcb67
Add unit tests for new data validation helper methods
Neluxx 9ae88fc
Add multi_rule_field to validation_test table
Neluxx 2cd3549
Update usage guide
Neluxx b5d9280
Update change log
Neluxx 61af269
Improve parameter documentation
Murl080 48634c8
Ignore dataValidation in `testDataValidationIsUnique()` to correctly …
Murl080 f384526
Apply suggestions from code review
Neluxx 1ef9241
Rename $expected to $notExpected in rule-dedicated methods
Neluxx eda5a28
Reword type validator docs to describe the asserted rule
Neluxx 03f2db8
Note that rule-dedicated helpers assert only their own rule
Neluxx 0a9b52d
Group custom expected tests next to their sibling test cases
Neluxx a8b30e6
Add dedicated test for testDataValidationContains helper
Neluxx ef99a91
Adjust unit tests
Neluxx 182cca4
Add dedicated test for assertDataValidationErrorsContain helper
Neluxx 7b01d41
Blank lines for code readability
ravage84 1d32199
CS
ravage84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ The `DataValidationTestTrait` provides helper methods to simplify testing the da | |
| ## Setup | ||
|
|
||
| Add the trait to any PHPUnit test case: | ||
|
|
||
| ```php | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
@@ -31,6 +32,7 @@ class ArticlesTableTest extends TestCase | |
| All helper methods are `protected` and callable from within your test class. | ||
|
|
||
| ## Example | ||
|
|
||
| ```php | ||
| public function testValidationTitle(): void | ||
| { | ||
|
|
@@ -53,27 +55,31 @@ Each helper builds an entity, runs the validator, and asserts the expected error | |
|
|
||
| ## Available methods | ||
|
|
||
| > **Note:** The presence, emptiness and type helpers listed below are rule-dedicated: each one only asserts that | ||
| > its own validation rule is (or is not) configured for the given field and ignores any other validation errors | ||
| > present on that field. They no longer compare against the field's full error list. | ||
|
|
||
| ### Presence and emptiness | ||
|
|
||
| - `testDataValidationRequired($table, $fieldName)` - field must be present. | ||
| - `testDataValidationNotRequired($table, $fieldName)` - field is optional. | ||
| - `testDataValidationNotEmpty($table, $fieldName)` - field cannot be `null` or `''`. | ||
| - `testDataValidationEmpty($table, $fieldName)` - field may be `null` or `''`. | ||
| - `testDataValidationRequired($table, $fieldName)` - asserts the field is configured to require presence (`_required`). | ||
| - `testDataValidationNotRequired($table, $fieldName)` - asserts the field is not configured to require presence. | ||
| - `testDataValidationNotEmpty($table, $fieldName)` - asserts the field is configured to disallow empty values, i.e. `null` or `''` (`_empty`). | ||
| - `testDataValidationEmpty($table, $fieldName)` - asserts the field is configured to allow empty values, i.e. `null` or `''`. | ||
|
|
||
| ### Type validators | ||
|
|
||
| - `testDataValidationBoolean($table, $fieldName)` - field must be boolean. | ||
| - `testDataValidationURLWithProtocol($table, $fieldName)` - requires `http://` or `https://`. | ||
| - `testDataValidationDateTime($table, $fieldName)` - field must be datetime. | ||
| - `testDataValidationDate($table, $fieldName)` - field must be date. | ||
| - `testDataValidationNaturalNumber($table, $fieldName)` - positive integers only. | ||
| - `testDataValidationScalar($table, $fieldName)` - rejects non-scalar values like arrays. | ||
| - `testDataValidationDecimal($table, $fieldName)` - rejects non-decimal values like arrays. | ||
| - `testDataValidationInteger($table, $fieldName)` - rejects non-integer values like arrays. | ||
| - `testDataValidationNonNegativeInteger($table, $fieldName)` - rejects negative integer values like `-1`. | ||
| - `testDataValidationGreaterThanOrEqual($table, $fieldName)` - rejects values below the threshold. | ||
| - `testDataValidationEmail($table, $fieldName)` - rejects invalid email addresses. | ||
| - `testDataValidationUuid($table, $fieldName)` - rejects invalid UUIDs. | ||
| - `testDataValidationBoolean($table, $fieldName)` - asserts the field is configured with the `boolean` validation rule. | ||
| - `testDataValidationURLWithProtocol($table, $fieldName)` - asserts the field is configured with the `urlWithProtocol` validation rule (requires `http://` or `https://`). | ||
| - `testDataValidationDateTime($table, $fieldName)` - asserts the field is configured with the `dateTime` validation rule. | ||
| - `testDataValidationDate($table, $fieldName)` - asserts the field is configured with the `date` validation rule. | ||
| - `testDataValidationNaturalNumber($table, $fieldName)` - asserts the field is configured with the `naturalNumber` validation rule (positive integers). | ||
| - `testDataValidationScalar($table, $fieldName)` - asserts the field is configured with the `scalar` validation rule. | ||
| - `testDataValidationDecimal($table, $fieldName)` - asserts the field is configured with the `decimal` validation rule. | ||
| - `testDataValidationInteger($table, $fieldName)` - asserts the field is configured with the `integer` validation rule. | ||
| - `testDataValidationNonNegativeInteger($table, $fieldName)` - asserts the field is configured with the `nonNegativeInteger` validation rule. | ||
| - `testDataValidationGreaterThanOrEqual($table, $fieldName, $threshold)` - asserts the field is configured with the `greaterThanOrEqual` validation rule. | ||
| - `testDataValidationEmail($table, $fieldName)` - asserts the field is configured with the `email` validation rule. | ||
| - `testDataValidationUuid($table, $fieldName)` - asserts the field is configured with the `uuid` validation rule. | ||
|
|
||
| ### Length validators | ||
|
|
||
|
|
@@ -83,9 +89,13 @@ Each helper builds an entity, runs the validator, and asserts the expected error | |
|
|
||
| ### Generic helpers | ||
|
|
||
| - `testDataValidation($table, $fieldName, $dataSet, $expected)` - the underlying helper. Use when no specialized helper fits. | ||
| - `testDataValidation($table, $fieldName, $dataSet, $expected)` - the underlying helper. Use when no specialized helper fits. Compares the field's **complete** error array against `$expected`. | ||
| - `testDataValidationContains($table, $fieldName, $dataSet, $expected)` - asserts the given `"rule name" => "message"` pairs are present on the field, ignoring any other errors. | ||
| - `testDataValidationNotContains($table, $fieldName, $dataSet, $rules)` - asserts the given rule names are **not** present on the field, ignoring any other errors. | ||
| - `testDataValidationNoErrors($table, $fieldName, $dataSet)` - asserts a data set produces no errors on the field. | ||
| - `testDataValidationInList($table, $list, $fieldName, $expected)` - runs the same assertion for each value in a list. | ||
| - `testDataValidationInList($table, $list, $fieldName, $expected)` - runs the complete-error-array assertion for each value in a list. | ||
| - `testDataValidationInListContains($table, $list, $fieldName, $expected)` - runs the `contains` assertion for each value in a list. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
| - `testDataValidationInListNotContains($table, $list, $fieldName, $rules)` - runs the `not contains` assertion for each value in a list. | ||
| - `testFullDataValidation($table, $dataSet, $expected)` - asserts errors across all fields. | ||
| - `testFullDataValidationNoErrors($table, $dataSet)` - asserts a full data set produces no errors at all. | ||
|
|
||
|
|
@@ -102,6 +112,7 @@ For application rules that run at save time (not marshalling time). These requir | |
| ## Dependent fields | ||
|
|
||
| Use the `$additionalDataSet` parameter to supply required companion fields so your test only fails for the reason you care about: | ||
|
|
||
| ```php | ||
| $this->testDataValidationNotEmpty( | ||
| $this->Articles, | ||
|
|
@@ -113,6 +124,7 @@ $this->testDataValidationNotEmpty( | |
| ## Passing `newEntity()` options | ||
|
|
||
| The `$options` parameter is forwarded to `Table::newEntity()`: | ||
|
|
||
| ```php | ||
| $this->testDataValidationRequired( | ||
| $this->Articles, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
InList`` is actually a type validation.
https://api.cakephp.org/5.3/class-Cake.Validation.Validation.html#inList()
Let's move it.