mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
fefe905e0b
When converting an object into an array, we exclude the message root message from it. Since we're using a convention to template those messages as an array, we could also use the same convention to return those messages. While working on it, I noticed that the name "__self__" wasn't reflecting what that really meant, so I renamed it "__root__" because it better reflects the meaning of those messages/templates. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
run([
|
|
'Two rules' => [v::allOf(v::intType(), v::negative()), '2'],
|
|
'Wrapped by "not"' => [v::not(v::allOf(v::intType(), v::positive())), 3],
|
|
'Wrapping "not"' => [v::allOf(v::not(v::intType()), v::greaterThan(2)), 4],
|
|
'With a single template' => [v::allOf(v::stringType(), v::arrayType()), 5, 'This is a single template'],
|
|
'With multiple templates' => [
|
|
v::allOf(v::stringType(), v::uppercase()),
|
|
5,
|
|
[
|
|
'__root__' => 'Two things are wrong',
|
|
'stringType' => 'Template for "stringType"',
|
|
'uppercase' => 'Template for "uppercase"',
|
|
],
|
|
],
|
|
]);
|
|
?>
|
|
--EXPECT--
|
|
Two rules
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
"2" must be of type integer
|
|
- All of the required rules must pass for "2"
|
|
- "2" must be of type integer
|
|
- "2" must be negative
|
|
[
|
|
'__root__' => 'All of the required rules must pass for "2"',
|
|
'intType' => '"2" must be of type integer',
|
|
'negative' => '"2" must be negative',
|
|
]
|
|
|
|
Wrapped by "not"
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
3 must not be of type integer
|
|
- These rules must not pass for 3
|
|
- 3 must not be of type integer
|
|
- 3 must not be positive
|
|
[
|
|
'__root__' => 'These rules must not pass for 3',
|
|
'intType' => '3 must not be of type integer',
|
|
'positive' => '3 must not be positive',
|
|
]
|
|
|
|
Wrapping "not"
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
4 must not be of type integer
|
|
- 4 must not be of type integer
|
|
[
|
|
'intType' => '4 must not be of type integer',
|
|
]
|
|
|
|
With a single template
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
This is a single template
|
|
- This is a single template
|
|
[
|
|
'allOf' => 'This is a single template',
|
|
]
|
|
|
|
With multiple templates
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
Template for "stringType"
|
|
- Two things are wrong
|
|
- Template for "stringType"
|
|
- Template for "uppercase"
|
|
[
|
|
'__root__' => 'Two things are wrong',
|
|
'stringType' => 'Template for "stringType"',
|
|
'uppercase' => 'Template for "uppercase"',
|
|
]
|
|
|