mirror of
https://github.com/Respect/Validation.git
synced 2026-03-14 22:35:45 +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.
47 lines
2.1 KiB
PHP
47 lines
2.1 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);
|
|
|
|
$input = ['email' => 'not an email'];
|
|
|
|
test('Results with a defined will display the name', catchMessage(
|
|
fn() => v::named('Number', v::intType())->assert($input),
|
|
fn(string $message) => expect($message)->toBe('Number must be an integer'),
|
|
));
|
|
|
|
test('Results with adjacent results defined will display the name', catchMessage(
|
|
fn() => v::named('Numbers', v::length(v::greaterThan(2)))->assert($input),
|
|
fn(string $message) => expect($message)->toBe('The length of Numbers must be greater than 2'),
|
|
));
|
|
|
|
test('Results with adjacent children results defined will display the name from its children', catchMessage(
|
|
fn() => v::named('Numbers', v::positive()->intType()->greaterThan(5))->assert($input),
|
|
fn(string $message) => expect($message)->toBe('Numbers must be a positive number'),
|
|
));
|
|
|
|
test('Results with a defined name cannot be overwritten by another name', catchMessage(
|
|
fn() => v::named('Foo', v::key('email', v::named('Email', v::email())))->assert($input),
|
|
fn(string $message) => expect($message)->toBe('Email must be an email address'),
|
|
));
|
|
|
|
test('Defining a name to a result with a path will add the path to the name', catchMessage(
|
|
fn() => v::named('Email', v::key('email', v::email()))->assert($input),
|
|
fn(string $message) => expect($message)->toBe('`.email` (<- Email) must be an email address'),
|
|
));
|
|
|
|
test('Results with a defined name will not be affected by a path', catchMessage(
|
|
fn() => v::key('email', v::named('Email', v::email()))->assert($input),
|
|
fn(string $message) => expect($message)->toBe('Email must be an email address'),
|
|
));
|
|
|
|
test('Not defining a name to a result with a path will display the path', catchMessage(
|
|
fn() => v::key('email', v::email())->assert($input),
|
|
fn(string $message) => expect($message)->toBe('`.email` must be an email address'),
|
|
));
|