mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 16:22:16 +02:00
fefe905e0b
When converting an object into an array, we exclude the message root message from it. Since we're using a convention to template those messages as an array, we could also use the same convention to return those messages. While working on it, I noticed that the name "__self__" wasn't reflecting what that really meant, so I renamed it "__root__" because it better reflects the meaning of those messages/templates. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
74 lines
2.8 KiB
PHP
74 lines
2.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Message\StandardFormatter;
|
|
|
|
use Respect\Validation\Result;
|
|
use Respect\Validation\Test\Builders\ResultBuilder;
|
|
use Respect\Validation\Validatable;
|
|
|
|
trait MainProvider
|
|
{
|
|
use ResultCreator;
|
|
|
|
/** @return array<string, array{0: Result, 1: string, 2?: array<string, mixed>}> */
|
|
public static function provideForMain(): array
|
|
{
|
|
return [
|
|
'without children, without templates' => [
|
|
(new ResultBuilder())->build(),
|
|
Validatable::TEMPLATE_STANDARD,
|
|
],
|
|
'without children, with templates' => [
|
|
(new ResultBuilder())->build(),
|
|
'This is a new template',
|
|
[(new ResultBuilder())->build()->id => 'This is a new template'],
|
|
],
|
|
'with children, without templates' => [
|
|
(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 children, with templates' => [
|
|
(new ResultBuilder())->id('parent')->template('__parent_original__')
|
|
->children(
|
|
(new ResultBuilder())->id('1st')->template('__1st_original__')->build(),
|
|
(new ResultBuilder())->id('1st')->template('__2nd_original__')->build(),
|
|
)
|
|
->build(),
|
|
'Parent custom',
|
|
[
|
|
'__root__' => 'Parent custom',
|
|
'1st' => '1st custom',
|
|
'2nd' => '2nd custom',
|
|
],
|
|
],
|
|
'with nested children, without templates' => [
|
|
(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__',
|
|
],
|
|
];
|
|
}
|
|
}
|