mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 00:02:33 +02:00
d7dc0f2b4e
This commit will rename the "Nullable" rule to "NullOr" while soft deprecating the old name. It should work the same as the previous one but with a different name. It will also prefix the result ID, allowing more message customization. While working on it, I realized that the prefix "nullOr" had a typo, and it was using "nullOf" instead. I fixed that, too. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
86 lines
1.8 KiB
PHP
86 lines
1.8 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
run([
|
|
'key' => [v::keyEquals('foo', 12), ['foo' => 10]],
|
|
'length' => [v::lengthGreaterThan(3), 'foo'],
|
|
'max' => [v::maxOdd(), [1, 2, 3, 4]],
|
|
'min' => [v::minEven(), [1, 2, 3]],
|
|
'not' => [v::notBetween(1, 3), 2],
|
|
'nullOr' => [v::nullOrBoolType(), 'string'],
|
|
'property' => [v::propertyBetween('foo', 1, 3), (object) ['foo' => 5]],
|
|
'undefOr' => [v::undefOrUrl(), 'string'],
|
|
]);
|
|
// phpcs:disable Generic.Files.LineLength.TooLong
|
|
?>
|
|
--EXPECT--
|
|
key
|
|
⎺⎺⎺
|
|
foo must equal 12
|
|
- foo must equal 12
|
|
[
|
|
'foo' => 'foo must equal 12',
|
|
]
|
|
|
|
length
|
|
⎺⎺⎺⎺⎺⎺
|
|
The length of "foo" must be greater than 3
|
|
- The length of "foo" must be greater than 3
|
|
[
|
|
'lengthGreaterThan' => 'The length of "foo" must be greater than 3',
|
|
]
|
|
|
|
max
|
|
⎺⎺⎺
|
|
As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number
|
|
- As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number
|
|
[
|
|
'maxOdd' => 'As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number',
|
|
]
|
|
|
|
min
|
|
⎺⎺⎺
|
|
As the minimum from `[1, 2, 3]`, 1 must be an even number
|
|
- As the minimum from `[1, 2, 3]`, 1 must be an even number
|
|
[
|
|
'minEven' => 'As the minimum from `[1, 2, 3]`, 1 must be an even number',
|
|
]
|
|
|
|
not
|
|
⎺⎺⎺
|
|
2 must not be between 1 and 3
|
|
- 2 must not be between 1 and 3
|
|
[
|
|
'notBetween' => '2 must not be between 1 and 3',
|
|
]
|
|
|
|
nullOr
|
|
⎺⎺⎺⎺⎺⎺
|
|
"string" must be of type boolean
|
|
- "string" must be of type boolean
|
|
[
|
|
'nullOrBoolType' => '"string" must be of type boolean',
|
|
]
|
|
|
|
property
|
|
⎺⎺⎺⎺⎺⎺⎺⎺
|
|
foo must be between 1 and 3
|
|
- foo must be between 1 and 3
|
|
[
|
|
'foo' => 'foo must be between 1 and 3',
|
|
]
|
|
|
|
undefOr
|
|
⎺⎺⎺⎺⎺⎺⎺
|
|
"string" must be a URL
|
|
- "string" must be a URL
|
|
[
|
|
'undefOrUrl' => '"string" must be a URL',
|
|
]
|