mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01:00
The `{{name}}` placeholder could represent different things depending on
the state of the Result, and referring to it as `{{name}}` seems
arbitrary. This commit changes it to `{{subject}}`, which is much more
generic and it describes well what that placeholder can mean.
40 lines
1.7 KiB
PHP
40 lines
1.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
test('Default mode', catchAll(
|
|
fn() => v::keyExists('foo')->assert(['bar' => 'baz']),
|
|
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('Inverted mode', catchAll(
|
|
fn() => v::not(v::keyExists('foo'))->assert(['foo' => 'baz']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must not be present')
|
|
->and($fullMessage)->toBe('- `.foo` must not be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` must not be present']),
|
|
));
|
|
|
|
test('Custom name', catchAll(
|
|
fn() => v::keyExists('foo')->setName('Custom name')->assert(['bar' => 'baz']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Custom name) must be present')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Custom name) must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Custom name) must be present']),
|
|
));
|
|
|
|
test('Custom template', catchAll(
|
|
fn() => v::keyExists('foo')->assert(['bar' => 'baz'], 'Custom template for {{subject}}'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Custom template for `.foo`')
|
|
->and($fullMessage)->toBe('- Custom template for `.foo`')
|
|
->and($messages)->toBe(['foo' => 'Custom template for `.foo`']),
|
|
));
|