mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
This commit introduces REUSE compliance by annotating all files with SPDX information and placing the reused licences in the LICENSES folder. We additionally removed the docheader tool which is made obsolete by this change. The main LICENSE and copyright text of the project is now not under my personal name anymore, and it belongs to "The Respect Project Contributors" instead. This change restores author names to several files, giving the appropriate attribution for contributions.
46 lines
2 KiB
PHP
46 lines
2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* 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 a valid 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 a valid 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 a valid 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 a valid email address'),
|
|
));
|