respect-validation/tests/feature/Issues/Issue1334Test.php
Henrique Moody 7c681fec66
Fix SPDX headers in all files
I ran the `bin/console spdx --fix` with different strategies for
different files. For most of the core classes, since they've been
drastically rebuilt, I've run it with the `git-blame` strategy, for for
the `src/Validators`, in which the API changed completely but the logic
remains the same, I use the `git-log` strategy.
2026-02-03 15:23:23 +01:00

52 lines
2.3 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
test('https://github.com/Respect/Validation/issues/1334', catchAll(
function (): void {
v::notBlank()->iterableType()->each(
v::key('street', v::stringType()->notBlank())
->key('region', v::stringType()->notBlank())
->key('country', v::stringType()->notBlank())
->keyOptional('other', v::nullOr(v::notBlank()->stringType())),
)->assert(
[
['region' => 'Oregon', 'country' => 'USA', 'other' => 123],
['street' => '', 'region' => 'Oregon', 'country' => 'USA'],
['street' => 123, 'region' => 'Oregon', 'country' => 'USA'],
],
);
},
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('`.0.street` must be present')
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
- Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid
- `.0` must pass the rules
- `.0.street` must be present
- `.0.other` must pass the rules
- `.0.other` must be a string or must be null
- `.1` must pass the rules
- `.1.street` must not be blank
- `.2` must pass the rules
- `.2.street` must be a string
FULL_MESSAGE)
->and($messages)->toBe([
'each' => [
'__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
0 => [
'__root__' => '`.0` must pass the rules',
'street' => '`.0.street` must be present',
'other' => '`.0.other` must be a string or must be null',
],
1 => '`.1.street` must not be blank',
2 => '`.2.street` must be a string',
],
]),
));