mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
We have seen users that want to change the default behavior of parameter stringifier: * Change the depth level shown from an array. * Change the number of elements shown from an array. * Not add quotes to some parameters. Because of that, this commit will allow users to customize the parameter stringifier. This commit will also update the documentation to instruct how to customize it. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
use Respect\Validation\Message\Formatter;
|
|
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
/**
|
|
* @covers \Respect\Validation\Exceptions\NestedValidationException
|
|
*
|
|
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
final class NestedValidationExceptionTest extends TestCase
|
|
{
|
|
/**
|
|
* @test
|
|
*/
|
|
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
|
|
{
|
|
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
|
$node = new IntValException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
|
$composite->addChild($node);
|
|
self::assertCount(1, $composite->getChildren());
|
|
self::assertContainsOnly(IntValException::class, $composite->getChildren());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function addingTheSameInstanceShouldAddJustOneSingleReference(): void
|
|
{
|
|
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
|
$node = new IntValException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
|
|
$composite->addChild($node);
|
|
$composite->addChild($node);
|
|
$composite->addChild($node);
|
|
self::assertCount(1, $composite->getChildren());
|
|
self::assertContainsOnly(IntValException::class, $composite->getChildren());
|
|
}
|
|
}
|