mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 23:05:45 +01:00
Currently, the templates that a user provides when running `assert()` can significantly impact how the message is displayed. Because of this, the formatters become complex as they all need to handle similar conditions to format results. This commit changes this behaviour, letting only the `InterpolationRenderer` handle the templates. This makes the code simpler and allows people to use the `InterpolationRenderer` directly, without needing to figure out how to handle templates. Thinking about it further, I believe handling templates is a concern for the `Renderer` anyway, and this will open the way to other improvements using the renderer. I also removed the exception that is thrown when the template is not a string, because I think that after validation has failed, we should not throw any other exceptions, as that could cause unexpected errors for users.
16 lines
471 B
PHP
16 lines
471 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
test('Scenario #1', catchFullMessage(
|
|
fn() => v::callback('is_string')->between(1, 2)->setTemplate('{{name}} is not tasty')->assert('something'),
|
|
fn(string $fullMessage) => expect($fullMessage)->toBe(<<<'FULL_MESSAGE'
|
|
- "something" is not tasty
|
|
- "something" must be between 1 and 2
|
|
FULL_MESSAGE),
|
|
));
|