mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Move template definitions to the rules
It's easier to identify the reason for choosing a specific message in the rule than in the exception. The same goes for the key we use to determine the templates. This change will simplify the `ValidationException` because it will already receive the template it needs to use. As a consequence, the `Factory` also becomes more straightforward. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
3334529591
commit
dd896bb12d
181 changed files with 1042 additions and 680 deletions
|
|
@ -15,6 +15,7 @@ use PHPUnit\Framework\Attributes\Test;
|
|||
use Respect\Validation\Message\Formatter;
|
||||
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
|
||||
use Respect\Validation\Test\TestCase;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
#[Group('core')]
|
||||
#[CoversClass(NestedValidationException::class)]
|
||||
|
|
@ -23,8 +24,8 @@ final class NestedValidationExceptionTest extends TestCase
|
|||
#[Test]
|
||||
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
|
||||
{
|
||||
$composite = new PropertyException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
||||
$node = new IntValException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
||||
$composite = $this->createNestedValidationException();
|
||||
$node = $this->createValidationException();
|
||||
$composite->addChild($node);
|
||||
self::assertCount(1, $composite->getChildren());
|
||||
self::assertContainsOnly(IntValException::class, $composite->getChildren());
|
||||
|
|
@ -33,12 +34,34 @@ final class NestedValidationExceptionTest extends TestCase
|
|||
#[Test]
|
||||
public function addingTheSameInstanceShouldAddJustOneSingleReference(): void
|
||||
{
|
||||
$composite = new PropertyException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
||||
$node = new IntValException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
||||
$composite = $this->createNestedValidationException();
|
||||
$node = $this->createValidationException();
|
||||
$composite->addChild($node);
|
||||
$composite->addChild($node);
|
||||
$composite->addChild($node);
|
||||
self::assertCount(1, $composite->getChildren());
|
||||
self::assertContainsOnly(IntValException::class, $composite->getChildren());
|
||||
}
|
||||
|
||||
public function createNestedValidationException(): NestedValidationException
|
||||
{
|
||||
return new NestedValidationException(
|
||||
input: 'input',
|
||||
id: 'id',
|
||||
params: [],
|
||||
template: Validatable::TEMPLATE_STANDARD,
|
||||
formatter: new Formatter('strval', new KeepOriginalStringName())
|
||||
);
|
||||
}
|
||||
|
||||
public function createValidationException(): IntValException
|
||||
{
|
||||
return new IntValException(
|
||||
input: 'input',
|
||||
id: 'id',
|
||||
params: [],
|
||||
template: Validatable::TEMPLATE_STANDARD,
|
||||
formatter: new Formatter('strval', new KeepOriginalStringName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue