respect-validation/tests/feature/Validators/MinTest.php
Henrique Moody 7c681fec66
Fix SPDX headers in all files
I ran the `bin/console spdx --fix` with different strategies for
different files. For most of the core classes, since they've been
drastically rebuilt, I've run it with the `git-blame` strategy, for for
the `src/Validators`, in which the API changed completely but the logic
remains the same, I use the `git-log` strategy.
2026-02-03 15:23:23 +01:00

59 lines
2.7 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-FileContributor: Dominick Johnson
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
test('Default', catchAll(
fn() => v::min(v::equals(1))->assert([2, 3]),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('The minimum of `[2, 3]` must be equal to 1')
->and($fullMessage)->toBe('- The minimum of `[2, 3]` must be equal to 1')
->and($messages)->toBe(['minEquals' => 'The minimum of `[2, 3]` must be equal to 1']),
));
test('Inverted', catchAll(
fn() => v::not(v::min(v::equals(1)))->assert([1, 2, 3]),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('The minimum of `[1, 2, 3]` must not be equal to 1')
->and($fullMessage)->toBe('- The minimum of `[1, 2, 3]` must not be equal to 1')
->and($messages)->toBe(['notMinEquals' => 'The minimum of `[1, 2, 3]` must not be equal to 1']),
));
test('With template', catchAll(
fn() => v::min(v::equals(1))->assert([2, 3], 'That did not go as planned'),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('That did not go as planned')
->and($fullMessage)->toBe('- That did not go as planned')
->and($messages)->toBe(['minEquals' => 'That did not go as planned']),
));
test('With name', catchAll(
fn() => v::named('Options', v::min(v::equals(1)))->assert([2, 3]),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('The minimum of Options must be equal to 1')
->and($fullMessage)->toBe('- The minimum of Options must be equal to 1')
->and($messages)->toBe(['minEquals' => 'The minimum of Options must be equal to 1']),
));
test('Chained wrapped rule', catchAll(
fn() => v::min(v::between(5, 7)->odd())->assert([2, 3, 4]),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('The minimum of `[2, 3, 4]` must be between 5 and 7')
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
- `[2, 3, 4]` must pass all the rules
- The minimum of `[2, 3, 4]` must be between 5 and 7
- The minimum of `[2, 3, 4]` must be an odd number
FULL_MESSAGE)
->and($messages)->toBe([
'__root__' => '`[2, 3, 4]` must pass all the rules',
'minBetween' => 'The minimum of `[2, 3, 4]` must be between 5 and 7',
'minOdd' => 'The minimum of `[2, 3, 4]` must be an odd number',
]),
));