mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
- Remove redundant "valid" prefix: Date, DateTime, DateTimeDiff, Domain, Email, Iban, Imei, Ip, Isbn, Json, LanguageCode, LeapDate, LeapYear, Luhn, MacAddress, NfeAccessKey, Nif, Nip, Pesel, Phone, Pis, PolishIdCard, PostalCode, Roman, Slug, Tld, Url, Uuid, Version. - Remove redundant "value" suffix ArrayVal, BoolVal, Countable, FloatVal, IntVal, IterableVal, NumericVal, ScalarVal, StringVal. - Standardize "consist only of" phrasing Alnum, Alpha, Cntrl, Consonant, Digit, Graph, Lowercase, Printable, Punct, Space, Spaced, Uppercase, Vowel, Xdigit. - Improve file accessibility messages Directory, Executable, File, Image, Readable, SymbolicLink, Writable. - Improve grammar and article usage CreditCard, Extension, Mimetype, Regex, Size.
61 lines
2.3 KiB
PHP
61 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/1469', catchAll(
|
|
fn() => v::init()
|
|
->arrayVal()
|
|
->keySet(
|
|
v::key(
|
|
'order_items',
|
|
v::init()
|
|
->arrayVal()
|
|
->each(
|
|
v::keySet(
|
|
v::key('product_title', v::stringVal()->notBlank()),
|
|
v::key('quantity', v::intVal()->notBlank()),
|
|
),
|
|
)
|
|
->notBlank(),
|
|
),
|
|
)
|
|
->assert([
|
|
'order_items' => [
|
|
[
|
|
'product_title' => 'test',
|
|
'quantity' => 'test',
|
|
],
|
|
['product_title2' => 'test'],
|
|
],
|
|
]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.order_items.0.quantity` must be an integer')
|
|
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
|
|
- Each item in `.order_items` must be valid
|
|
- `.order_items.0` validation failed
|
|
- `.order_items.0.quantity` must be an integer
|
|
- `.order_items.1` contains both missing and extra keys
|
|
- `.order_items.1.product_title` must be present
|
|
- `.order_items.1.quantity` must be present
|
|
- `.order_items.1.product_title2` must not be present
|
|
FULL_MESSAGE)
|
|
->and($messages)->toBe([
|
|
'keySet' => [
|
|
'__root__' => 'Each item in `.order_items` must be valid',
|
|
0 => '`.order_items.0.quantity` must be an integer',
|
|
1 => [
|
|
'__root__' => '`.order_items.1` contains both missing and extra keys',
|
|
'product_title' => '`.order_items.1.product_title` must be present',
|
|
'quantity' => '`.order_items.1.quantity` must be present',
|
|
'product_title2' => '`.order_items.1.product_title2` must not be present',
|
|
],
|
|
],
|
|
]),
|
|
));
|