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.
84 lines
3.9 KiB
PHP
84 lines
3.9 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);
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
test('All', catchAll(
|
|
fn() => v::allStringType()->assert(['foo', 12, 'bar']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Every item in `["foo", 12, "bar"]` must be a string')
|
|
->and($fullMessage)->toBe('- Every item in `["foo", 12, "bar"]` must be a string')
|
|
->and($messages)->toBe(['allStringType' => 'Every item in `["foo", 12, "bar"]` must be a string']),
|
|
));
|
|
|
|
test('Key', catchAll(
|
|
fn() => v::keyEquals('foo', 12)->assert(['foo' => 10]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be equal to 12')
|
|
->and($fullMessage)->toBe('- `.foo` must be equal to 12')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be equal to 12']),
|
|
));
|
|
|
|
test('Length', catchAll(
|
|
fn() => v::lengthGreaterThan(3)->assert('foo'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The length of "foo" must be greater than 3')
|
|
->and($fullMessage)->toBe('- The length of "foo" must be greater than 3')
|
|
->and($messages)->toBe(['lengthGreaterThan' => 'The length of "foo" must be greater than 3']),
|
|
));
|
|
|
|
test('Max', catchAll(
|
|
fn() => v::maxOdd()->assert([1, 2, 3, 4]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The maximum of `[1, 2, 3, 4]` must be an odd number')
|
|
->and($fullMessage)->toBe('- The maximum of `[1, 2, 3, 4]` must be an odd number')
|
|
->and($messages)->toBe(['maxOdd' => 'The maximum of `[1, 2, 3, 4]` must be an odd number']),
|
|
));
|
|
|
|
test('Min', catchAll(
|
|
fn() => v::minEven()->assert([1, 2, 3]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The minimum of `[1, 2, 3]` must be an even number')
|
|
->and($fullMessage)->toBe('- The minimum of `[1, 2, 3]` must be an even number')
|
|
->and($messages)->toBe(['minEven' => 'The minimum of `[1, 2, 3]` must be an even number']),
|
|
));
|
|
|
|
test('Not', catchAll(
|
|
fn() => v::notBetween(1, 3)->assert(2),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('2 must not be between 1 and 3')
|
|
->and($fullMessage)->toBe('- 2 must not be between 1 and 3')
|
|
->and($messages)->toBe(['notBetween' => '2 must not be between 1 and 3']),
|
|
));
|
|
|
|
test('NullOr', catchAll(
|
|
fn() => v::nullOrBoolType()->assert('string'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('"string" must be a boolean or must be null')
|
|
->and($fullMessage)->toBe('- "string" must be a boolean or must be null')
|
|
->and($messages)->toBe(['nullOrBoolType' => '"string" must be a boolean or must be null']),
|
|
));
|
|
|
|
test('Property', catchAll(
|
|
fn() => v::propertyBetween('foo', 1, 3)->assert((object) ['foo' => 5]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be between 1 and 3')
|
|
->and($fullMessage)->toBe('- `.foo` must be between 1 and 3')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be between 1 and 3']),
|
|
));
|
|
|
|
test('UndefOr', catchAll(
|
|
fn() => v::undefOrUrl()->assert('string'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('"string" must be a URL or must be undefined')
|
|
->and($fullMessage)->toBe('- "string" must be a URL or must be undefined')
|
|
->and($messages)->toBe(['undefOrUrl' => '"string" must be a URL or must be undefined']),
|
|
));
|