mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
The `setTemplate()` method can be confusing, as it can be tricky for someone to determine which chain is being templated. Using the `Templated` rule makes this much more explicit and adds a little bit of verbosity. For users, this will be a significant change, but there are easy ways to update this code in their projects, so I’m not overly concerned about it. Another benefit of this change is that it makes the `Validator` much simpler, as it no longer needs to track the template. This change also makes the `Reducer` simpler, for similar reasons to the `Validator`. However, because the `Validator` is simpler, we can remove the code that the `Reducer` had to meet the specific needs of the `Validator`.
15 lines
416 B
PHP
15 lines
416 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Respect\Validation\Validator;
|
|
|
|
test('Scenario #1', catchMessage(function (): void {
|
|
v::templated(Validator::callback('is_int')->between(1, 2), '{{subject}} is not tasty')->assert('something');
|
|
},
|
|
fn(string $message) => expect($message)->toBe('"something" is not tasty')));
|