mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 14:55:44 +01:00
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.
114 lines
5.5 KiB
PHP
114 lines
5.5 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('Missing key', catchAll(
|
|
fn() => v::key('foo', v::intType())->assert([]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be present')
|
|
->and($fullMessage)->toBe('- `.foo` must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be present']),
|
|
));
|
|
|
|
test('Default', catchAll(
|
|
fn() => v::key('foo', v::intType())->assert(['foo' => 'string']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` must be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be an integer']),
|
|
));
|
|
|
|
test('Inverted', catchAll(
|
|
fn() => v::not(v::key('foo', v::intType()))->assert(['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must not be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` must not be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` must not be an integer']),
|
|
));
|
|
|
|
test('Double-inverted with missing key', catchAll(
|
|
fn() => v::not(v::not(v::key('foo', v::intType())))->assert([]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be present')
|
|
->and($fullMessage)->toBe('- `.foo` must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be present']),
|
|
));
|
|
|
|
test('With wrapped name, missing key', catchAll(
|
|
fn() => v::key('foo', v::named('Wrapped', v::intType()))->assert([]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Wrapped must be present')
|
|
->and($fullMessage)->toBe('- Wrapped must be present')
|
|
->and($messages)->toBe(['foo' => 'Wrapped must be present']),
|
|
));
|
|
|
|
test('With wrapped name, default', catchAll(
|
|
fn() => v::named('Wrapper', v::key('foo', v::named('Wrapped', v::intType())))->assert(['foo' => 'string']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Wrapped must be an integer')
|
|
->and($fullMessage)->toBe('- Wrapped must be an integer')
|
|
->and($messages)->toBe(['foo' => 'Wrapped must be an integer']),
|
|
));
|
|
|
|
test('With wrapped name, inverted', catchAll(
|
|
fn() => v::named('Not', v::not(v::named('Wrapper', v::key('foo', v::named('Wrapped', v::intType())))))->assert(['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Wrapped must not be an integer')
|
|
->and($fullMessage)->toBe('- Wrapped must not be an integer')
|
|
->and($messages)->toBe(['foo' => 'Wrapped must not be an integer']),
|
|
));
|
|
|
|
test('With wrapper name, default', catchAll(
|
|
fn() => v::named('Wrapper', v::key('foo', v::intType()))->assert(['foo' => 'string']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Wrapper) must be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Wrapper) must be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Wrapper) must be an integer']),
|
|
));
|
|
|
|
test('With wrapper name, missing key', catchAll(
|
|
fn() => v::named('Wrapper', v::key('foo', v::intType()))->assert([]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Wrapper) must be present')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Wrapper) must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Wrapper) must be present']),
|
|
));
|
|
|
|
test('With wrapper name, inverted', catchAll(
|
|
fn() => v::named('Not', v::not(v::named('Wrapper', v::key('foo', v::intType()))))->assert(['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Wrapper) must not be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Wrapper) must not be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Wrapper) must not be an integer']),
|
|
));
|
|
|
|
test('With "Not" name, inverted', catchAll(
|
|
fn() => v::named('Not', v::not(v::key('foo', v::intType())))->assert(['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Not) must not be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Not) must not be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Not) must not be an integer']),
|
|
));
|
|
|
|
test('With template, default', catchAll(
|
|
fn() => v::key('foo', v::intType())->assert(['foo' => 'string'], 'That key is off-key'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('That key is off-key')
|
|
->and($fullMessage)->toBe('- That key is off-key')
|
|
->and($messages)->toBe(['foo' => 'That key is off-key']),
|
|
));
|
|
|
|
test('With template, inverted', catchAll(
|
|
fn() => v::not(v::key('foo', v::intType()))->assert(['foo' => 12], 'No off-key key'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('No off-key key')
|
|
->and($fullMessage)->toBe('- No off-key key')
|
|
->and($messages)->toBe(['foo' => 'No off-key key']),
|
|
));
|