mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 14:55:44 +01:00
I ran the `bin/console spdx --fix` with different strategies for different files. For most of the core classes, since they've been drastically rebuilt, I've run it with the `git-blame` strategy, for for the `src/Validators`, in which the API changed completely but the logic remains the same, I use the `git-log` strategy.
74 lines
2.8 KiB
PHP
74 lines
2.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* 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\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Respect\Validation\Message\StandardFormatter\ResultCreator;
|
|
use Respect\Validation\Result;
|
|
use Respect\Validation\Test\Builders\ResultBuilder;
|
|
use Respect\Validation\Test\Message\TestingMessageRenderer;
|
|
use Respect\Validation\Test\TestCase;
|
|
use Respect\Validation\Validator;
|
|
|
|
#[CoversClass(FirstResultStringFormatter::class)]
|
|
final class FirstResultStringFormatterTest extends TestCase
|
|
{
|
|
use ResultCreator;
|
|
|
|
/** @param array<string, mixed> $templates */
|
|
#[Test]
|
|
#[DataProvider('provideForMain')]
|
|
public function itShouldFormatMainMessage(Result $result, string $expected, array $templates = []): void
|
|
{
|
|
$renderer = new TestingMessageRenderer();
|
|
$formatter = new FirstResultStringFormatter();
|
|
|
|
self::assertSame($expected, $formatter->format($result, $renderer, $templates));
|
|
}
|
|
|
|
/** @return array<string, array{0: Result, 1: string, 2?: array<string, mixed>}> */
|
|
public static function provideForMain(): array
|
|
{
|
|
return [
|
|
'without children' => [
|
|
(new ResultBuilder())->build(),
|
|
Validator::TEMPLATE_STANDARD,
|
|
],
|
|
'with children' => [
|
|
(new ResultBuilder())
|
|
->id('parent')->id('parent')->template('__parent_original__')
|
|
->children(
|
|
(new ResultBuilder())->id('1st')->template('__1st_original__')->build(),
|
|
(new ResultBuilder())->id('1st')->template('__2nd_original__')->build(),
|
|
)
|
|
->build(),
|
|
'__1st_original__',
|
|
],
|
|
'with nested children' => [
|
|
(new ResultBuilder())->id('parent')->template('__parent_original__')
|
|
->children(
|
|
(new ResultBuilder())->id('1st')->template('__1st_original__')
|
|
->children(
|
|
(new ResultBuilder())->id('1st_1st')->template('__1st_1st_original__')->build(),
|
|
(new ResultBuilder())->id('1st_2nd')->template('__1st_2nd_original__')->build(),
|
|
)
|
|
->build(),
|
|
(new ResultBuilder())->id('1st')->template('__2nd_original__')->build(),
|
|
)
|
|
->build(),
|
|
'__1st_1st_original__',
|
|
],
|
|
];
|
|
}
|
|
}
|