respect-validation/tests/integration/rules/keySet.phpt
Henrique Moody 99dc8720ce
Update the validation engine of wrapper-based rules
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-22 18:44:32 +01:00

49 lines
1.6 KiB
PHP

--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
$input = ['foo' => 42, 'bar' => 'String'];
$missingKeys = v::create()
->keySet(
v::key('foo', v::intVal()),
v::key('bar', v::stringType()),
v::key('baz', v::boolType())
);
$extraKeys = v::create()
->keySet(
v::key('foo', v::intVal()),
v::key('bar', v::stringType()),
);
$correctStructure = v::create()
->keySet(
v::key('foo', v::stringType()),
v::key('bar', v::intType()),
);
exceptionMessage(static fn() => $missingKeys->assert(false));
exceptionMessage(static fn() => $missingKeys->assert($input));
exceptionMessage(static fn() => $extraKeys->assert($input + ['baz' => true]));
exceptionMessage(static fn() => $correctStructure->assert($input));
exceptionFullMessage(static fn() => $missingKeys->assert(false));
exceptionFullMessage(static fn() => $missingKeys->assert($input));
exceptionFullMessage(static fn() => $extraKeys->assert($input + ['baz' => true]));
exceptionFullMessage(static fn() => $correctStructure->assert($input));
?>
--EXPECT--
`false` must be of type array
Must have keys `["baz"]` in `["foo": 42, "bar": "String"]`
Must not have keys `["baz"]` in `["foo": 42, "bar": "String", "baz": true]`
foo must be of type string
- `false` must be of type array
- Must have keys `["baz"]` in `["foo": 42, "bar": "String"]`
- Must not have keys `["baz"]` in `["foo": 42, "bar": "String", "baz": true]`
- All of the required rules must pass for `["foo": 42, "bar": "String"]`
- foo must be of type string
- bar must be of type integer