respect-validation/tests/feature/Issues/Issue799Test.php
Alexandre Gomes Gaigalas 16148e9593 Standardize and improve validation message templates
- 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.
2026-02-03 19:58:55 +00:00

48 lines
1.7 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);
use Respect\Validation\Test\Stubs\CountableStub;
$input = 'http://www.google.com/search?q=respect.github.com';
test('https://github.com/Respect/Validation/issues/799 | #1', catchAll(
fn() => v::init()
->after(
[new CountableStub(1), 'count'],
v::arrayVal()->key('scheme', v::startsWith('https')),
)
->assert($input),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('1 must be an array')
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
- 1 must pass all the rules
- 1 must be an array
- `.scheme` must be present
FULL_MESSAGE)
->and($messages)->toBe([
'__root__' => '1 must pass all the rules',
'arrayVal' => '1 must be an array',
'scheme' => '`.scheme` must be present',
]),
));
test('https://github.com/Respect/Validation/issues/799 | #2', catchAll(
fn() => v::init()
->after(
fn($url) => parse_url((string) $url),
v::arrayVal()->key('scheme', v::startsWith('https')),
)
->assert($input),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('`.scheme` must start with "https"')
->and($fullMessage)->toBe('- `.scheme` must start with "https"')
->and($messages)->toBe(['scheme' => '`.scheme` must start with "https"']),
));