mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 14:55: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.
50 lines
2.3 KiB
PHP
50 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('Default', catchAll(
|
|
fn() => v::phone()->assert('123'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('"123" must be a phone number')
|
|
->and($fullMessage)->toBe('- "123" must be a phone number')
|
|
->and($messages)->toBe(['phone' => '"123" must be a phone number']),
|
|
));
|
|
|
|
test('Country-specific', catchAll(
|
|
fn() => v::phone('BR')->assert('+1 650 253 00 00'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('"+1 650 253 00 00" must be a phone number for country Brazil')
|
|
->and($fullMessage)->toBe('- "+1 650 253 00 00" must be a phone number for country Brazil')
|
|
->and($messages)->toBe(['phone' => '"+1 650 253 00 00" must be a phone number for country Brazil']),
|
|
));
|
|
|
|
test('Inverted', catchAll(
|
|
fn() => v::not(v::phone())->assert('+55 11 91111 1111'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('"+55 11 91111 1111" must not be a phone number')
|
|
->and($fullMessage)->toBe('- "+55 11 91111 1111" must not be a phone number')
|
|
->and($messages)->toBe(['notPhone' => '"+55 11 91111 1111" must not be a phone number']),
|
|
));
|
|
|
|
test('Default with name', catchAll(
|
|
fn() => v::named('Phone', v::phone())->assert('123'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Phone must be a phone number')
|
|
->and($fullMessage)->toBe('- Phone must be a phone number')
|
|
->and($messages)->toBe(['phone' => 'Phone must be a phone number']),
|
|
));
|
|
|
|
test('Country-specific with name', catchAll(
|
|
fn() => v::named('Phone', v::phone('US'))->assert('123'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Phone must be a phone number for country United States')
|
|
->and($fullMessage)->toBe('- Phone must be a phone number for country United States')
|
|
->and($messages)->toBe(['phone' => 'Phone must be a phone number for country United States']),
|
|
));
|