respect-validation/tests/feature/Validators/LazyTest.php
Alexandre Gomes Gaigalas d9cdc118b2 Introduce REUSE compliance
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.
2026-01-21 06:28:11 +00:00

73 lines
3.5 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
test('Default', catchAll(
fn() => v::lazy(fn() => v::intType())->assert(true),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('`true` must be an integer')
->and($fullMessage)->toBe('- `true` must be an integer')
->and($messages)->toBe(['intType' => '`true` must be an integer']),
));
test('Inverted', catchAll(
fn() => v::not(v::lazy(fn() => v::intType()))->assert(2),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('2 must not be an integer')
->and($fullMessage)->toBe('- 2 must not be an integer')
->and($messages)->toBe(['notIntType' => '2 must not be an integer']),
));
test('With created name, default', catchAll(
fn() => v::named('Wrapper', v::lazy(fn() => v::named('Created', v::intType())))->assert(true),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Created must be an integer')
->and($fullMessage)->toBe('- Created must be an integer')
->and($messages)->toBe(['intType' => 'Created must be an integer']),
));
test('With wrapper name, default', catchAll(
fn() => v::named('Wrapper', v::lazy(fn() => v::intType()))->assert(true),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Wrapper must be an integer')
->and($fullMessage)->toBe('- Wrapper must be an integer')
->and($messages)->toBe(['intType' => 'Wrapper must be an integer']),
));
test('With created name, inverted', catchAll(
fn() => v::named('Not', v::not(v::named('Wrapped', v::lazy(fn() => v::named('Created', v::intType())))))->assert(2),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Created must not be an integer')
->and($fullMessage)->toBe('- Created must not be an integer')
->and($messages)->toBe(['notIntType' => 'Created must not be an integer']),
));
test('With wrapper name, inverted', catchAll(
fn() => v::named('Not', v::not(v::named('Wrapped', v::lazy(fn() => v::intType()))))->assert(2),
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(['notIntType' => 'Wrapped must not be an integer']),
));
test('With not name, inverted', catchAll(
fn() => v::named('Not', v::not(v::lazy(fn() => v::intType())))->assert(2),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Not must not be an integer')
->and($fullMessage)->toBe('- Not must not be an integer')
->and($messages)->toBe(['notIntType' => 'Not must not be an integer']),
));
test('With template, default', catchAll(
fn() => v::lazy(fn() => v::intType())->assert(true, 'Lazy lizards lounging like lords in the local lagoon'),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Lazy lizards lounging like lords in the local lagoon')
->and($fullMessage)->toBe('- Lazy lizards lounging like lords in the local lagoon')
->and($messages)->toBe(['intType' => 'Lazy lizards lounging like lords in the local lagoon']),
));