mirror of
https://github.com/Respect/Validation.git
synced 2026-03-18 08:09:51 +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.
84 lines
3.8 KiB
PHP
84 lines
3.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Dominick Johnson
|
|
* 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']),
|
|
));
|