respect-validation/tests/feature/SetTemplateWithMultipleValidatorsShouldUseTemplateAsMainMessageTest.php
Henrique Moody d9380588e7
Remove the setTemplate() method from Validator
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`.
2026-01-02 15:45:23 +01:00

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')));