respect-validation/tests/feature/Validators/TemplatedTest.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

50 lines
2.3 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('Default', catchAll(
fn() => v::templated('Template in "Templated"', v::stringType())->assert(12),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Template in "Templated"')
->and($fullMessage)->toBe('- Template in "Templated"')
->and($messages)->toBe(['stringType' => 'Template in "Templated"']),
));
test('With parameters', catchAll(
fn() => v::templated('Template in {{source}}', v::stringType(), ['source' => 'Templated'])->assert(12),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Template in "Templated"')
->and($fullMessage)->toBe('- Template in "Templated"')
->and($messages)->toBe(['stringType' => 'Template in "Templated"']),
));
test('Inverted', catchAll(
fn() => v::not(v::templated('Template in "Templated"', v::intType()))->assert(12),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Template in "Templated"')
->and($fullMessage)->toBe('- Template in "Templated"')
->and($messages)->toBe(['notIntType' => 'Template in "Templated"']),
));
test('Template passed to Validator::assert()', catchAll(
fn() => v::templated('Template in "Templated"', v::stringType())->assert(10, 'Template in "Validator::assert"'),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Template in "Validator::assert"')
->and($fullMessage)->toBe('- Template in "Validator::assert"')
->and($messages)->toBe(['stringType' => 'Template in "Validator::assert"']),
));
test('With bound', catchAll(
fn() => v::templated('Template in "Templated"', v::attributes())->assert(null),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('Template in "Templated"')
->and($fullMessage)->toBe('- Template in "Templated"')
->and($messages)->toBe(['attributes' => 'Template in "Templated"']),
));