mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Respect\Validation\Rules\ArrayType;
|
|
use Respect\Validation\Rules\BoolType;
|
|
use Respect\Validation\Rules\Each;
|
|
use Respect\Validation\Rules\KeyOptional;
|
|
use Respect\Validation\Rules\OneOf;
|
|
use Respect\Validation\Rules\StringType;
|
|
use Respect\Validation\Rules\StringVal;
|
|
use Respect\Validation\Validator;
|
|
|
|
test('https://github.com/Respect/Validation/issues/1289', catchAll(
|
|
fn() => Validator::create(
|
|
new Each(
|
|
Validator::create(
|
|
new KeyOptional(
|
|
'default',
|
|
new OneOf(
|
|
new StringType(),
|
|
new BoolType(),
|
|
),
|
|
),
|
|
new KeyOptional(
|
|
'description',
|
|
new StringVal(),
|
|
),
|
|
new KeyOptional(
|
|
'children',
|
|
new ArrayType(),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
->assert([
|
|
[
|
|
'default' => 2,
|
|
'description' => [],
|
|
'children' => ['nope'],
|
|
],
|
|
]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.0.default` must be a string')
|
|
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
|
|
- `.0` must pass the rules
|
|
- `.default` must pass one of the rules
|
|
- `.default` must be a string
|
|
- `.default` must be a boolean
|
|
- `.description` must be a string value
|
|
FULL_MESSAGE)
|
|
->and($messages)->toBe([
|
|
0 => [
|
|
'__root__' => '`.0` must pass the rules',
|
|
'default' => [
|
|
'__root__' => '`.default` must pass one of the rules',
|
|
'stringType' => '`.default` must be a string',
|
|
'boolType' => '`.default` must be a boolean',
|
|
],
|
|
'description' => '`.description` must be a string value',
|
|
],
|
|
]),
|
|
));
|