mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
Add more tests for Each rule
This commit is contained in:
parent
6d3b518185
commit
e465810efe
1 changed files with 52 additions and 0 deletions
|
|
@ -239,3 +239,55 @@ test('With array template and name, default', expectAll(
|
|||
'intType.3' => 'Wrapped must be an integer',
|
||||
]
|
||||
));
|
||||
|
||||
test('Chained wrapped rule', expectAll(
|
||||
fn() => v::each(v::between(5, 7)->odd())->assert([2, 4]),
|
||||
'2 must be between 5 and 7',
|
||||
<<<'FULL_MESSAGE'
|
||||
- Each item in `[2, 4]` must be valid
|
||||
- All of the required rules must pass for 2
|
||||
- 2 must be between 5 and 7
|
||||
- 2 must be an odd number
|
||||
- All of the required rules must pass for 4
|
||||
- 4 must be between 5 and 7
|
||||
- 4 must be an odd number
|
||||
FULL_MESSAGE,
|
||||
[
|
||||
'__root__' => 'Each item in `[2, 4]` must be valid',
|
||||
'allOf.1' => [
|
||||
'__root__' => 'All of the required rules must pass for 2',
|
||||
'between' => '2 must be between 5 and 7',
|
||||
'odd' => '2 must be an odd number',
|
||||
],
|
||||
'allOf.2' => [
|
||||
'__root__' => 'All of the required rules must pass for 4',
|
||||
'between' => '4 must be between 5 and 7',
|
||||
'odd' => '4 must be an odd number',
|
||||
],
|
||||
]
|
||||
));
|
||||
|
||||
test('Multiple nested rules', expectAll(
|
||||
fn() => v::each(v::arrayType()->key('my_int', v::intType()->odd()))->assert([['not_int' => 'wrong'], ['my_int' => 2], 'not an array']),
|
||||
'my_int must be present',
|
||||
<<<'FULL_MESSAGE'
|
||||
- Each item in `[["not_int": "wrong"], ["my_int": 2], "not an array"]` must be valid
|
||||
- These rules must pass for `["not_int": "wrong"]`
|
||||
- my_int must be present
|
||||
- These rules must pass for `["my_int": 2]`
|
||||
- my_int must be an odd number
|
||||
- All of the required rules must pass for "not an array"
|
||||
- "not an array" must be an array
|
||||
- my_int must be present
|
||||
FULL_MESSAGE,
|
||||
[
|
||||
'__root__' => 'Each item in `[["not_int": "wrong"], ["my_int": 2], "not an array"]` must be valid',
|
||||
'allOf.1' => 'my_int must be present',
|
||||
'allOf.2' => 'my_int must be an odd number',
|
||||
'allOf.3' => [
|
||||
'__root__' => 'All of the required rules must pass for "not an array"',
|
||||
'arrayType' => '"not an array" must be an array',
|
||||
'my_int' => 'my_int must be present',
|
||||
],
|
||||
]
|
||||
));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue