-
Notifications
You must be signed in to change notification settings - Fork 773
Expand file tree
/
Copy pathIssue1289Test.php
More file actions
70 lines (66 loc) · 2.38 KB
/
Issue1289Test.php
File metadata and controls
70 lines (66 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
use Respect\Validation\ValidatorBuilder;
use Respect\Validation\Validators\ArrayType;
use Respect\Validation\Validators\BoolType;
use Respect\Validation\Validators\Each;
use Respect\Validation\Validators\KeyOptional;
use Respect\Validation\Validators\OneOf;
use Respect\Validation\Validators\StringType;
use Respect\Validation\Validators\StringVal;
test('https://github.com/Respect/Validation/issues/1289', catchAll(
fn() => ValidatorBuilder::init(
new Each(
ValidatorBuilder::init(
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()
// Currently we're getting `.0.default.default` instead of `.0.default`
// that is happening the result has multiple children, and they're not inheriting the path from their
// parent, but instead, the parent is duplicating the children's path.
->and($message)->toBe('`.0.default` must be a string')
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
- `.0` must pass the rules
- `.0.default` must pass one of the rules
- `.0.default` must be a string
- `.0.default` must be a boolean
- `.0.description` must be a string value
FULL_MESSAGE)
->and($messages)->toBe([
0 => [
'__root__' => '`.0` must pass the rules',
'default' => [
'`.0.default` must be a string',
'`.0.default` must be a boolean',
],
'description' => '`.0.description` must be a string value',
],
]),
));