mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
I've moved almost all the code for placeholder replacement and parameter modifiers into an external library called Respect\StringFormatter. This approach allows us to evolve the template capabilities without making major changes to the Validation's code. This commit will introduce another dependency, `respect/string-formatter`, and will upgrade the version of `respect/string-formatter`, which simplifies our internal API greatly. While making this change, I also updated how we generate exceptions. Instead of rendering the full message and the array of messages, we delegate that creation to the `ResultQuery`, which improves performance because we don’t need to render those big messages unless the user actually needs them.
32 lines
946 B
PHP
32 lines
946 B
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Message\Formatter;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Respect\Validation\Path;
|
|
use Respect\Validation\Test\Builders\ResultBuilder;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
#[CoversClass(TemplateResolver::class)]
|
|
final class TemplateResolverTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function itShouldReturnResultWithTemplateWhenKeyExists(): void
|
|
{
|
|
$result = (new ResultBuilder())->path(new Path('foo-path'))->build();
|
|
$templates = ['foo-path' => 'My custom template'];
|
|
$sut = new TemplateResolver();
|
|
$template = $sut->getGivenTemplate($result, $templates);
|
|
|
|
self::assertSame('My custom template', $template);
|
|
}
|
|
}
|